add type selector
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Владимир Фёдоров 2023-09-24 15:09:27 +07:00
parent d982952955
commit 1d4b5380af
6 changed files with 32 additions and 8 deletions

View File

@ -10,7 +10,7 @@
}, },
"dependencies": { "dependencies": {
"html2canvas": "^1.4.1", "html2canvas": "^1.4.1",
"pinia": "^2.1.4", "pinia": "^2.1.6",
"vue": "3.3.4" "vue": "3.3.4"
}, },
"devDependencies": { "devDependencies": {

View File

@ -12,6 +12,7 @@ import { ButtonSize, InputType } from "./types";
import { useStore } from "./store"; import { useStore } from "./store";
import { storeToRefs } from "pinia"; import { storeToRefs } from "pinia";
import { VARIANTS_VERTICAL_ROTATION, VARIANTS_IMAGE_SIZE } from './const'; import { VARIANTS_VERTICAL_ROTATION, VARIANTS_IMAGE_SIZE } from './const';
import { ref } from "vue";
const store = useStore(); const store = useStore();
@ -28,6 +29,8 @@ const {
imageHeight, imageHeight,
} = storeToRefs(store); } = storeToRefs(store);
const typeSelector = ref('rus');
const savePng = async () => { const savePng = async () => {
const canvas = document.getElementById("canvas") as HTMLCanvasElement; const canvas = document.getElementById("canvas") as HTMLCanvasElement;
@ -52,7 +55,7 @@ const savePng = async () => {
<Input v-model="vMargin" :min="1">Отступ, мм</Input> <Input v-model="vMargin" :min="1">Отступ, мм</Input>
<Input v-model="vRotation" :min="0" :max="359">Поворот, градусы</Input> <Input v-model="vRotation" :min="0" :max="359">Поворот, градусы</Input>
<ButtonsBar> <ButtonsBar>
<Button v-for="deg in VARIANTS_VERTICAL_ROTATION" :key="deg" :size="ButtonSize.Small" :click="() => store.setVRotation(deg)"> <Button v-for="deg in VARIANTS_VERTICAL_ROTATION" :key="deg" :active="vRotation == deg" :size="ButtonSize.Small" :click="() => store.setVRotation(deg)">
{{ deg }}° {{ deg }}°
</Button> </Button>
</ButtonsBar> </ButtonsBar>
@ -74,6 +77,12 @@ const savePng = async () => {
</SidebarBlock> </SidebarBlock>
</Sidebar> </Sidebar>
<Page> <Page>
<div id="typeSelector">
<Button :size="ButtonSize.Small" :active="typeSelector == 'rus'"
:click="() => { typeSelector = 'rus' }">Пропись</Button>
<Button :size="ButtonSize.Small" :active="typeSelector == 'math'"
:click="() => { typeSelector = 'math' }">Математика</Button>
</div>
<Canvas /> <Canvas />
</Page> </Page>
<Sidebar horizontalPosition="right"> <Sidebar horizontalPosition="right">
@ -85,6 +94,7 @@ const savePng = async () => {
v-for="size in VARIANTS_IMAGE_SIZE" v-for="size in VARIANTS_IMAGE_SIZE"
:key="size.name" :key="size.name"
:size="ButtonSize.Small" :size="ButtonSize.Small"
:active="imageWidth == size.width && imageHeight == size.height || imageWidth == size.height && imageHeight == size.width"
:click="() => store.setImageSize(size)" :click="() => store.setImageSize(size)"
> >
{{ size.name }} {{ size.name }}
@ -102,4 +112,9 @@ const savePng = async () => {
</template> </template>
<style scoped> <style scoped>
#typeSelector {
display: flex;
justify-content: center;
margin-top: 20px;
}
</style> </style>

View File

@ -4,10 +4,12 @@ import { ButtonSize } from '../types';
interface Props { interface Props {
click: (payload?: MouseEvent) => void; click: (payload?: MouseEvent) => void;
size?: ButtonSize; size?: ButtonSize;
active: boolean;
} }
withDefaults(defineProps<Props>(), { withDefaults(defineProps<Props>(), {
size: ButtonSize.Medium, size: ButtonSize.Medium,
active: false,
}) })
</script> </script>
@ -16,6 +18,7 @@ withDefaults(defineProps<Props>(), {
:class="{ :class="{
button: true, button: true,
'button--small': size === ButtonSize.Small, 'button--small': size === ButtonSize.Small,
'active': active === true,
}" }"
@click="click" @click="click"
> >
@ -45,4 +48,8 @@ withDefaults(defineProps<Props>(), {
font-size: 10pt; font-size: 10pt;
width: auto; width: auto;
} }
.active {
background-color: #ffce99;
}
</style> </style>

View File

@ -119,6 +119,6 @@ watch(store, () => {
canvas { canvas {
border: 1px solid black; border: 1px solid black;
margin: 20px; margin: 20px;
height: calc(100vh - 40px); height: calc(100vh - 100px);
} }
</style> </style>

View File

@ -2,7 +2,9 @@
</script> </script>
<template> <template>
<div>
<slot></slot> <slot></slot>
</div>
</template> </template>
<style scoped> <style scoped>

View File

@ -386,10 +386,10 @@ picocolors@^1.0.0:
resolved "https://registry.yarnpkg.com/picocolors/-/picocolors-1.0.0.tgz#cb5bdc74ff3f51892236eaf79d68bc44564ab81c" resolved "https://registry.yarnpkg.com/picocolors/-/picocolors-1.0.0.tgz#cb5bdc74ff3f51892236eaf79d68bc44564ab81c"
integrity sha512-1fygroTLlHu66zi26VoTDv8yRgm0Fccecssto+MhsZ0D/DGW2sm8E8AjW7NU5VVTRt5GxbeZ5qBuJr+HyLYkjQ== integrity sha512-1fygroTLlHu66zi26VoTDv8yRgm0Fccecssto+MhsZ0D/DGW2sm8E8AjW7NU5VVTRt5GxbeZ5qBuJr+HyLYkjQ==
pinia@^2.1.4: pinia@^2.1.6:
version "2.1.4" version "2.1.6"
resolved "https://registry.yarnpkg.com/pinia/-/pinia-2.1.4.tgz#a642adfe6208e10c36d3dc16184a91064788142a" resolved "https://registry.yarnpkg.com/pinia/-/pinia-2.1.6.tgz#e88959f14b61c4debd9c42d0c9944e2875cbe0fa"
integrity sha512-vYlnDu+Y/FXxv1ABo1vhjC+IbqvzUdiUC3sfDRrRyY2CQSrqqaa+iiHmqtARFxJVqWQMCJfXx1PBvFs9aJVLXQ== integrity sha512-bIU6QuE5qZviMmct5XwCesXelb5VavdOWKWaB17ggk++NUwQWWbP5YnsONTk3b752QkW9sACiR81rorpeOMSvQ==
dependencies: dependencies:
"@vue/devtools-api" "^6.5.0" "@vue/devtools-api" "^6.5.0"
vue-demi ">=0.14.5" vue-demi ">=0.14.5"