Skip to content

Commit

Permalink
feat:add tip (#107)
Browse files Browse the repository at this point in the history
* feat: radio add disabledTip
  • Loading branch information
Yolanda-psc authored Sep 12, 2024
1 parent 455dc68 commit e9133e4
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 18 deletions.
5 changes: 5 additions & 0 deletions .changeset/olive-swans-remember.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'dangoui': patch
---

feat: add disabled tip
7 changes: 7 additions & 0 deletions docs/assets/component-meta/meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -3058,6 +3058,13 @@
"type": "boolean",
"default": "false"
},
{
"name": "disabledTip",
"description": "当前无法选中的提示内容",
"required": false,
"type": "string",
"default": "\"\""
},
{
"name": "inline",
"description": "",
Expand Down
58 changes: 43 additions & 15 deletions docs/content/3.input/4.radio.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ title: 使用
<PreviewBlock title="禁用">
<div>
<DuRadio disabled :checked="true" />
<DuRadio disabled />
<DuRadio disabled :disabledTip="'当前不可选中'" />
</div>
</PreviewBlock>
</template>
Expand All @@ -71,16 +71,17 @@ function handleMonthlyUpdate(e: { checked: boolean }) {
}
</script>
```

::

::demo
---
title: 使用 RadioGroup
---
## ::demo

## title: 使用 RadioGroup

一般来说,你会选择使用 RadioGroup

#snippet

```vue
<template>
<PreviewBlock title="一组值">
Expand Down Expand Up @@ -110,22 +111,28 @@ const inlineSelected = ref('')
const buttonInlineSelected = ref('')
</script>
```

::

::demo
---
title: 不同颜色
---
## ::demo

## title: 不同颜色

#snippet

```vue
<template>
<PreviewBlock title="secondary">
<div class="flex flex-col gap-y-8px">
<DuRadioGroup color="secondary" v-model:value="selected" inline>
<DuRadio v-for="item in items" :label="item" :value="item" />
</DuRadioGroup>
<DuRadioGroup color="secondary" v-model:value="selected" inline shape="button">
<DuRadioGroup
color="secondary"
v-model:value="selected"
inline
shape="button"
>
<DuRadio v-for="item in items" :label="item" :value="item" />
</DuRadioGroup>
</div>
Expand All @@ -135,7 +142,12 @@ title: 不同颜色
<DuRadioGroup color="success" v-model:value="selected" inline>
<DuRadio v-for="item in items" :label="item" :value="item" />
</DuRadioGroup>
<DuRadioGroup color="success" v-model:value="selected" inline shape="button">
<DuRadioGroup
color="success"
v-model:value="selected"
inline
shape="button"
>
<DuRadio v-for="item in items" :label="item" :value="item" />
</DuRadioGroup>
</div>
Expand All @@ -145,7 +157,12 @@ title: 不同颜色
<DuRadioGroup color="warning" v-model:value="selected" inline>
<DuRadio v-for="item in items" :label="item" :value="item" />
</DuRadioGroup>
<DuRadioGroup color="warning" v-model:value="selected" inline shape="button">
<DuRadioGroup
color="warning"
v-model:value="selected"
inline
shape="button"
>
<DuRadio v-for="item in items" :label="item" :value="item" />
</DuRadioGroup>
</div>
Expand All @@ -155,7 +172,12 @@ title: 不同颜色
<DuRadioGroup color="error" v-model:value="selected" inline>
<DuRadio v-for="item in items" :label="item" :value="item" />
</DuRadioGroup>
<DuRadioGroup color="error" v-model:value="selected" inline shape="button">
<DuRadioGroup
color="error"
v-model:value="selected"
inline
shape="button"
>
<DuRadio v-for="item in items" :label="item" :value="item" />
</DuRadioGroup>
</div>
Expand All @@ -165,7 +187,12 @@ title: 不同颜色
<DuRadioGroup color="trade" v-model:value="selected" inline>
<DuRadio v-for="item in items" :label="item" :value="item" />
</DuRadioGroup>
<DuRadioGroup color="trade" v-model:value="selected" inline shape="button">
<DuRadioGroup
color="trade"
v-model:value="selected"
inline
shape="button"
>
<DuRadio v-for="item in items" :label="item" :value="item" />
</DuRadioGroup>
</div>
Expand All @@ -180,6 +207,7 @@ const items = ['月卡', '季卡', '年卡']
const selected = ref('')
</script>
```

::

## API
Expand All @@ -188,4 +216,4 @@ const selected = ref('')
::

::api{component="RadioGroup" :withPrefix="true"}
::
::
13 changes: 10 additions & 3 deletions packages/dangoui/src/radio/Radio.vue
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ import {
groupValueInjectionKey,
setGroupValueInjectionKey,
} from './helpers'
import { useToast } from '../composables/useToast'
const props = withDefaults(
defineProps<{
Expand All @@ -76,6 +77,7 @@ const props = withDefaults(
custom?: boolean
inline?: boolean
disabled?: boolean
disabledTip?: string
cell?: boolean
value?: any
valueKey?: string
Expand All @@ -94,9 +96,10 @@ const props = withDefaults(
disabled: false,
cell: false,
color: undefined,
disabledTip: '',
},
)
const toast = useToast()
const emit = defineEmits<{
(e: 'click', event: any): void
(e: 'input', value: { checked: boolean; value: any | undefined }): void
Expand All @@ -116,6 +119,7 @@ const config = computed(() => {
inline,
custom,
disabled,
disabledTip,
shape,
cell,
value,
Expand All @@ -124,14 +128,14 @@ const config = computed(() => {
} = {
...props,
}
return {
extStyle,
extClass,
label,
inline: inline || groupConfig?.value.inline || false,
custom: custom || groupConfig?.value.custom || false,
disabled,
disabledTip: disabledTip || '',
shape: shape || groupConfig?.value.shape || 'normal',
cell: cell || groupConfig?.value.cell || false,
value,
Expand Down Expand Up @@ -184,7 +188,10 @@ function update(value: string | number) {
function handleClick(event: any) {
emit('click', event)
if (config.value.disabled) {
if (config.value.disabled && config.value.disabledTip) {
toast.show({
message: config.value.disabledTip,
})
return
}
Expand Down

0 comments on commit e9133e4

Please sign in to comment.