Skip to content

Commit

Permalink
feat: Add a description field to the options of the picker component.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ayideyia committed Jul 6, 2024
1 parent 70688f3 commit 6672e5d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 18 deletions.
38 changes: 25 additions & 13 deletions frontend/src/components/Picker/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import useI18n from '@/lang'
interface Props {
type: 'single' | 'multi'
title: string
options: { label: string; value: string }[]
options: { label: string; value: string; description?: string }[]
initialValue?: string[]
}
Expand Down Expand Up @@ -62,14 +62,17 @@ const handleSelectAll = () => {

<div class="options">
<div v-for="(o, i) in options" :key="i" @click="handleSelect(o.value)" class="item">
<span>{{ o.label }}</span>
<Icon
v-show="isSelected(o.value)"
:size="32"
icon="selected"
fill="var(--primary-color)"
style="flex-shrink: 0"
/>
<div class="label">
<div>{{ o.label }}</div>
<Icon
v-show="isSelected(o.value)"
:size="32"
icon="selected"
fill="var(--primary-color)"
style="flex-shrink: 0"
/>
</div>
<div class="description">{{ o.description }}</div>
</div>
</div>

Expand Down Expand Up @@ -108,11 +111,7 @@ const handleSelectAll = () => {
overflow: auto;
}
.item {
display: flex;
align-items: center;
justify-content: space-between;
margin: 4px 0;
line-height: 32px;
padding: 0 8px;
word-wrap: break-word;
word-break: break-all;
Expand All @@ -122,6 +121,19 @@ const handleSelectAll = () => {
&:nth-child(even) {
background: var(--table-tr-even-bg);
}
.label {
display: flex;
align-items: center;
justify-content: space-between;
line-height: 32px;
}
.description {
font-size: 12px;
line-height: 22px;
opacity: 0.7;
}
}
}
</style>
2 changes: 1 addition & 1 deletion frontend/src/hooks/usePicker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { render, createVNode } from 'vue'

import PickerComp from '@/components/Picker/index.vue'

type PickerItem = { label: string; value: string }
type PickerItem = { label: string; value: string; description?: string }

const createPicker = (
type: 'single' | 'multi',
Expand Down
8 changes: 4 additions & 4 deletions frontend/src/views/PlaygroundView/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ const handleShowSinglePicker = async () => {
const res = await picker.single(
'Single',
[
{ label: 'ONE', value: 'one' },
{ label: 'ONE', value: 'one', description: 'The first option' },
{ label: 'TWO', value: 'two' },
{ label: 'THREE', value: 'three' }
{ label: 'THREE', value: 'three', description: 'The third option' }
],
['one']
)
Expand All @@ -53,9 +53,9 @@ const handleShowMultiPicker = async () => {
const res = await picker.multi(
'Multi',
[
{ label: 'ONE', value: 'one' },
{ label: 'ONE', value: 'one', description: 'The first option' },
{ label: 'TWO', value: 'two' },
{ label: 'THREE', value: 'three' }
{ label: 'THREE', value: 'three', description: 'The third option' }
],
['one', 'three']
)
Expand Down

0 comments on commit 6672e5d

Please sign in to comment.