Skip to content

Commit

Permalink
Gather all styles of BSMap components into one SCSS module
Browse files Browse the repository at this point in the history
It's much clear than split into individual SFCs
  • Loading branch information
xingrz committed Apr 6, 2024
1 parent 485bdd1 commit 2d947dc
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 81 deletions.
9 changes: 2 additions & 7 deletions src/components/BSMap.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<div :class="$style.map" :style="style">
<div :class="$bsMap.map" :style="style">
<BSRow v-for="(row, index) in rows" :key="index" :src="row" :row="index" />
</div>
</template>
Expand All @@ -13,6 +13,7 @@ import {
import { max } from 'radash';
import $bsMap from './BSMap/style.module.scss';
import BSRow from './BSMap/BSRow.vue';
const props = defineProps<{
Expand All @@ -28,9 +29,3 @@ const style = computed(() => ({
'--bs-map-cols': cols.value,
}) as CSSProperties);
</script>

<style lang="scss" module>
.map {
line-height: calc(var(--bs-map-size) * 1px);
}
</style>
12 changes: 2 additions & 10 deletions src/components/BSMap/BSCell.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<BSSelectable v-slot="{ selectable }" :row="props.row" :offset="props.offset" :length="props.src.length">
<div :class="[selectable, $style.cell]" :title="props.src" @click="handleClick" :style="style">
<div :class="[selectable, $bsMap.cell]" :title="props.src" @click="handleClick" :style="style">
<BSIcon v-for="(icon, index) in (parts?.icons || [])" :key="index" :src="icon"
@ratio="(ratio: number) => updateRatio(index, ratio)" />
</div>
Expand All @@ -18,6 +18,7 @@ import {
import { useEditorStore } from '@/stores/editor';
import styleFromParams from '@/utils/styleFromParams';
import $bsMap from './style.module.scss';
import BSSelectable from './BSSelectable.vue';
import BSIcon from './BSIcon.vue';
Expand Down Expand Up @@ -62,12 +63,3 @@ function updateRatio(layer: number, newRatio: number): void {
}
}
</script>
<style lang="scss" module>
.cell {
position: relative;
cursor: pointer;
width: calc(var(--bs-map-size) * var(--bs-map-cell-ratio, 1) * 1px);
height: calc(var(--bs-map-size) * 1px);
}
</style>
29 changes: 4 additions & 25 deletions src/components/BSMap/BSIcon.vue
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<template>
<div v-if="parts.type == 'text'" :class="$style.text" :style="style">
<div v-if="parts.type == 'text'" :class="$bsMap.text" :style="style">
<span>{{ parts.data }}</span>
</div>
<img v-else :class="$style.icon" :style="style" :src="parts.data" />
<img v-else :class="$bsMap.icon" :style="style" :src="parts.data" />
</template>

<script lang="ts" setup>
Expand All @@ -17,6 +17,8 @@ import {
import { useIconStore } from '@/stores/icon';
import styleFromParams from '@/utils/styleFromParams';
import $bsMap from './style.module.scss';
const props = defineProps<{
src: string;
}>();
Expand Down Expand Up @@ -76,26 +78,3 @@ function selectTextWidth(flag: string): number | undefined {
}
}
</script>

<style lang="scss" module>
.icon,
.text {
position: absolute;
user-select: none;
width: calc(var(--bs-map-size) * var(--bs-map-icon-ratio, 1) * 1px);
height: calc(var(--bs-map-size) * 1px);
}
.text {
font-family: monospace;
font-size: calc(var(--bs-map-size) / 2 * 1px);
text-align: var(--bs-map-cell-halign, center);
z-index: 1; // texts are always stacked over icons
span {
line-height: 1;
vertical-align: var(--bs-map-cell-valign, middle);
}
}
</style>
25 changes: 4 additions & 21 deletions src/components/BSMap/BSRow.vue
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<template>
<div :class="$style.row">
<div :class="$style.cells" :style="rowStyle">
<div :class="$bsMap.row">
<div :class="$bsMap.cells" :style="rowStyle">
<BSCell v-for="({ part, offset }, index) in cells" :key="index" :src="part" :row="row" :offset="offset" />
</div>
<div :class="$style.texts">
<div :class="$bsMap.texts">
<BSText v-for="({ part, offset, align }, index) in texts" :key="index" :src="part" :align="align" :row="row"
:offset="offset" />
</div>
Expand All @@ -16,6 +16,7 @@ import { computed, defineProps } from 'vue';
import splitWithOffset from '@/utils/splitWithOffset';
import styleFromParams from '@/utils/styleFromParams';
import $bsMap from './style.module.scss';
import BSCell from './BSCell.vue';
import BSText from './BSText.vue';
Expand All @@ -38,21 +39,3 @@ const texts = computed(() => parts.value.texts
const rowStyle = computed(() => styleFromParams(parts.value.texts[4]?.part));
</script>

<style lang="scss" module>
.row {
display: flex;
align-items: stretch;
}
.cells {
flex: 0 0 calc(var(--bs-map-size) * var(--bs-map-cols) * 1px);
display: flex;
justify-content: center;
}
.texts {
flex: 1 1 auto;
display: flex;
}
</style>
20 changes: 2 additions & 18 deletions src/components/BSMap/BSText.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<BSSelectable v-slot="{ selectable }" :row="props.row" :offset="props.offset" :length="props.src.length">
<div :class="[selectable, $style.text]" :data-align="align" :title="props.src" @click="handleClick">
<div :class="[selectable, $bsMap.text]" :data-align="align" :title="props.src" @click="handleClick">
{{ props.src }}
</div>
</BSSelectable>
Expand All @@ -11,6 +11,7 @@ import { defineProps } from 'vue';
import { useEditorStore } from '@/stores/editor';
import $bsMap from './style.module.scss';
import BSSelectable from './BSSelectable.vue';
const props = defineProps<{
Expand All @@ -31,20 +32,3 @@ function handleClick(): void {
};
}
</script>

<style lang="scss" module>
.text {
user-select: none;
cursor: pointer;
margin: 0 5px;
font-family: monospace;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
&[data-align="4"] {
flex-grow: 1;
text-align: end;
}
}
</style>
62 changes: 62 additions & 0 deletions src/components/BSMap/style.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
.map {
line-height: calc(var(--bs-map-size) * 1px);

.row {
display: flex;
align-items: stretch;

.cells {
flex: 0 0 calc(var(--bs-map-size) * var(--bs-map-cols) * 1px);
display: flex;
justify-content: center;

.cell {
position: relative;
cursor: pointer;
width: calc(var(--bs-map-size) * var(--bs-map-cell-ratio, 1) * 1px);
height: calc(var(--bs-map-size) * 1px);

.icon,
.text {
position: absolute;
user-select: none;

width: calc(var(--bs-map-size) * var(--bs-map-icon-ratio, 1) * 1px);
height: calc(var(--bs-map-size) * 1px);
}

.text {
font-family: monospace;
font-size: calc(var(--bs-map-size) / 2 * 1px);
text-align: var(--bs-map-cell-halign, center);
z-index: 1; // texts are always stacked over icons

span {
line-height: 1;
vertical-align: var(--bs-map-cell-valign, middle);
}
}
}
}

.texts {
flex: 1 1 auto;
display: flex;

.text {
user-select: none;
cursor: pointer;
margin: 0 5px;
font-family: monospace;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;

&[data-align="4"] {
flex-grow: 1;
text-align: end;
}
}
}
}
}

0 comments on commit 2d947dc

Please sign in to comment.