-
Notifications
You must be signed in to change notification settings - Fork 6
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
Feat/bcc range component #327
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
@layer components { | ||
.bcc-range { | ||
@apply flex flex-col gap-2 w-full; | ||
} | ||
|
||
.bcc-range__label { | ||
@apply text-base text-center text-gray-900; | ||
} | ||
|
||
.bcc-range__container { | ||
@apply flex flex-col items-center gap-2 w-full; | ||
} | ||
|
||
.bcc-range__slider-container { | ||
@apply w-full; | ||
} | ||
|
||
.bcc-range__text { | ||
@apply text-sm text-gray-700 whitespace-nowrap; | ||
} | ||
|
||
.bcc-range__input { | ||
@apply w-full h-1 bg-gray-200 rounded appearance-none cursor-pointer; | ||
@apply disabled:opacity-50 disabled:cursor-not-allowed; | ||
-webkit-appearance: none; | ||
appearance: none; | ||
} | ||
|
||
.bcc-range__labels { | ||
@apply flex items-center gap-4 w-full justify-between; | ||
} | ||
|
||
.bcc-range__input:disabled { | ||
@apply bg-gray-400 cursor-not-allowed; | ||
} | ||
|
||
.bcc-range__input::-webkit-slider-thumb { | ||
-webkit-appearance: none; | ||
@apply w-4 h-4 mt-[-6px] rounded-full bg-white cursor-pointer bg-white; | ||
box-shadow: 0 1px 2px 0px rgba(113, 113, 113, 0.5), | ||
0 0 0 2px rgba(226, 232, 240, 1); | ||
} | ||
|
||
.bcc-range__input::-webkit-slider-runnable-track { | ||
@apply h-1 rounded bg-gray-200 border-red-200; | ||
} | ||
|
||
.bcc-range__input::-moz-range-thumb { | ||
@apply w-4 h-4 rounded-full bg-red-900 cursor-pointer border-0; | ||
} | ||
|
||
.bcc-range__input::-moz-range-track { | ||
@apply h-1 rounded bg-gray-200; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { describe, it, expect } from "vitest"; | ||
|
||
import { mount } from "@vue/test-utils"; | ||
import BccRange from "./BccRange.vue"; | ||
|
||
describe("BccRange", () => { | ||
it("renders a range input", () => { | ||
const wrapper = mount(BccRange, { | ||
props: { modelValue: 0, min: -100, max: 10, step: 1 }, | ||
}); | ||
expect(wrapper.html()).toMatchSnapshot(); | ||
}); | ||
|
||
it("renders a label", () => { | ||
const wrapper = mount(BccRange, { | ||
props: { label: "Test label", modelValue: 0, min: -10, max: 10, step: 1 }, | ||
}); | ||
expect(wrapper.text()).toBe("Test label"); | ||
expect(wrapper.html()).toMatchSnapshot(); | ||
}); | ||
|
||
it("handles a v-model", async () => { | ||
const wrapper = mount(BccRange, { | ||
props: { modelValue: 0, min: -10, max: 10, step: 1 }, | ||
}); | ||
await wrapper.find("input").trigger("input"); | ||
|
||
expect(wrapper.emitted("update:modelValue")?.length).toBe(1); | ||
expect(wrapper.emitted("update:modelValue")![0]).toEqual([0]); | ||
}); | ||
}); |
93 changes: 93 additions & 0 deletions
93
design-library/src/components/BccRange/BccRange.stories.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import BccRange from "./BccRange.vue"; | ||
|
||
import type { Meta, StoryFn } from "@storybook/vue3"; | ||
|
||
export default { | ||
title: "Forms/BccRange", | ||
component: BccRange, | ||
argTypes: { | ||
modelValue: { | ||
description: "The current value of the range slider", | ||
}, | ||
min: { | ||
description: "The minimum value of the range slider", | ||
}, | ||
max: { | ||
description: "The maximum value of the range slider", | ||
}, | ||
step: { | ||
description: "The step value of the range slider", | ||
}, | ||
label: { | ||
description: "The main label of the range slider", | ||
}, | ||
leftLabel: { | ||
description: "The label of the left side of the range slider", | ||
}, | ||
rightLabel: { | ||
description: "The label of the right side of the range slider", | ||
}, | ||
disabled: { | ||
description: "Whether the range slider is disabled", | ||
}, | ||
}, | ||
} as Meta<typeof BccRange>; | ||
|
||
const Template: StoryFn<typeof BccRange> = (args) => ({ | ||
components: { BccRange }, | ||
setup() { | ||
return { args }; | ||
}, | ||
template: ` | ||
<BccRange label="Did you have the correct amount of people?" leftLabel="Less people" rightLabel="More people" /> | ||
`, | ||
}); | ||
|
||
export const Example = Template.bind({}); | ||
Example.args = { | ||
modelValue: 0, | ||
min: -10, | ||
max: 10, | ||
step: 1, | ||
label: "Range Slider", | ||
leftLabel: "Less people", | ||
rightLabel: "More people", | ||
disabled: false, | ||
}; | ||
Example.parameters = { | ||
docs: { | ||
source: { | ||
language: "html", | ||
code: ` | ||
<BccRange label="Did you have the correct amount of people?" leftLabel="Less people" rightLabel="More people" />`, | ||
}, | ||
}, | ||
}; | ||
|
||
export const Disabled: StoryFn<typeof BccRange> = () => ({ | ||
components: { BccRange }, | ||
template: ` | ||
<BccRange label="Did you have the correct amount of people?" leftLabel="Less people" rightLabel="More people" disabled /> | ||
`, | ||
}); | ||
|
||
export const WithoutSideLabels: StoryFn<typeof BccRange> = () => ({ | ||
components: { BccRange }, | ||
template: ` | ||
<BccRange label="Did you have the correct amount of people?" /> | ||
`, | ||
}); | ||
|
||
export const WithCustomRange: StoryFn<typeof BccRange> = () => ({ | ||
components: { BccRange }, | ||
template: ` | ||
<BccRange label="Did you have the correct amount of people?" leftLabel="Less people" rightLabel="More people" min=-100 max=100 step=5 /> | ||
`, | ||
}); | ||
|
||
export const StartFromLeft: StoryFn<typeof BccRange> = () => ({ | ||
components: { BccRange }, | ||
template: ` | ||
<BccRange label="Did you have the correct amount of people?" leftLabel="Less people" rightLabel="More people" modelValue=0 min=0 max=10 /> | ||
`, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<script setup lang="ts"> | ||
type Props = { | ||
modelValue: number; | ||
min: number; | ||
max: number; | ||
step: number; | ||
label?: string; | ||
leftLabel?: string; | ||
rightLabel?: string; | ||
disabled?: boolean; | ||
}; | ||
|
||
withDefaults(defineProps<Props>(), { | ||
min: -10, | ||
max: 10, | ||
step: 1, | ||
disabled: false, | ||
}); | ||
|
||
const emit = defineEmits(["update:modelValue"]); | ||
|
||
const handleInput = (event: Event) => { | ||
const target = event.target as HTMLInputElement; | ||
emit("update:modelValue", Number(target.value)); | ||
}; | ||
</script> | ||
|
||
<template> | ||
<div class="bcc-range"> | ||
<label v-if="label" class="bcc-range__label">{{ label }}</label> | ||
<div class="bcc-range__container"> | ||
<div class="bcc-range__slider-container"> | ||
<input | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add focus state, styling should show that it is selected in a subtle way. |
||
type="range" | ||
class="bcc-range__input" | ||
:min="min" | ||
:max="max" | ||
:step="step" | ||
:value="modelValue" | ||
:disabled="disabled" | ||
@input="handleInput" | ||
/> | ||
</div> | ||
<div class="bcc-range__labels"> | ||
<span v-if="leftLabel" class="bcc-range__text bcc-range__text--left">{{ leftLabel }}</span> | ||
<span v-if="rightLabel" class="bcc-range__text bcc-range__text--right">{{ | ||
rightLabel | ||
}}</span> | ||
</div> | ||
</div> | ||
</div> | ||
</template> |
26 changes: 26 additions & 0 deletions
26
design-library/src/components/BccRange/__snapshots__/BccRange.spec.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html | ||
|
||
exports[`BccRange > renders a label 1`] = ` | ||
"<div class="bcc-range"><label class="bcc-range__label">Test label</label> | ||
<div class="bcc-range__container"> | ||
<div class="bcc-range__slider-container"><input type="range" class="bcc-range__input" min="-10" max="10" step="1"></div> | ||
<div class="bcc-range__labels"> | ||
<!--v-if--> | ||
<!--v-if--> | ||
</div> | ||
</div> | ||
</div>" | ||
`; | ||
|
||
exports[`BccRange > renders a range input 1`] = ` | ||
"<div class="bcc-range"> | ||
<!--v-if--> | ||
<div class="bcc-range__container"> | ||
<div class="bcc-range__slider-container"><input type="range" class="bcc-range__input" min="-100" max="10" step="1"></div> | ||
<div class="bcc-range__labels"> | ||
<!--v-if--> | ||
<!--v-if--> | ||
</div> | ||
</div> | ||
</div>" | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need a label.