Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

プリセットの管理ダイアログのリデザイン #2418

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open
33 changes: 33 additions & 0 deletions src/components/Base/BaseSlider.stories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import type { Meta, StoryObj } from "@storybook/vue3";

import { ref } from "vue";
import BaseSlider from "./BaseSlider.vue";

const meta: Meta<typeof BaseSlider> = {
component: BaseSlider,
args: {
modelValue: 50,
min: 0,
max: 100,
step: 1,
},
render: (args) => ({
components: { BaseSlider },
setup() {
const model = ref(Number(args.modelValue));
return { args, model };
},
template: `<BaseSlider v-bind="args" v-model="model"></BaseSlider>`,
}),
};

export default meta;
type Story = StoryObj<typeof BaseSlider>;

export const Default: Story = {};

export const Disabled: Story = {
args: {
disabled: true,
},
};
97 changes: 97 additions & 0 deletions src/components/Base/BaseSlider.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<template>
<SliderRoot
class="SliderRoot"
:min
:max
:step
:disabled
:modelValue="[model]"
@update:modelValue="
(value) => value != undefined && $emit('update:modelValue', value[0])
"
Comment on lines +9 to +11
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

radix-vue、なんでundefinedが来る仕様なんだろう・・・ 😇
とりあえずエラーの握りつぶしになっている(ドツボにはまるととても厄介)ので、エラー出すようにしますか!

Suggested change
@update:modelValue="
(value) => value != undefined && $emit('update:modelValue', value[0])
"
@update:modelValue="
(value) => {
if (value == undefined) {
throw new Error('Undefined value received');
}
$emit('update:modelValue', value[0]);
}
"

>
<SliderTrack class="SliderTrack">
<SliderRange class="SliderRange" />
</SliderTrack>
<SliderThumb class="SliderThumb" />
</SliderRoot>
</template>

<script setup lang="ts">
import { SliderRange, SliderRoot, SliderThumb, SliderTrack } from "radix-vue";

defineProps<{
min?: number;
max?: number;
step?: number;
disabled?: boolean;
modelValue: number;
}>();

defineEmits<{
"update:modelValue": [value: number];
}>();

const model = defineModel<number>({ required: true });
</script>

<style lang="scss">
@use "@/styles/v2/variables" as vars;
@use "@/styles/v2/colors" as colors;
@use "@/styles/v2/mixin" as mixin;

.SliderRoot {
position: relative;
display: flex;
align-items: center;
height: vars.$size-control;
cursor: grab;

&:active {
cursor: grabbing;
}

&[data-disabled] {
opacity: 0.5;
cursor: not-allowed;
}
}

.SliderTrack {
background-color: colors.$border;
position: relative;
flex-grow: 1;
border-radius: 9999px;
height: 4px;
}

.SliderRange {
position: absolute;
background-color: colors.$primary;
border-radius: 9999px;
height: 100%;
}

.SliderThumb {
display: block;
width: 8px;
height: vars.$size-indicator;
background-color: colors.$primary;
border: 1px solid colors.$border;
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
border-radius: vars.$radius-1;

:hover:not([data-disabled]) > & {
background-color: colors.$primary-hovered;
}

:active:not([data-disabled]) > & {
background-color: colors.$primary-pressed;
box-shadow: 0 0 0 transparent;
}

&:focus-visible {
@include mixin.on-focus;
}
}
</style>
Loading
Loading