action select: add disabled option state
This commit is contained in:
@@ -4,6 +4,7 @@
|
|||||||
| { component: Component; props: Record<string, any> }
|
| { component: Component; props: Record<string, any> }
|
||||||
| Snippet<[opt: ActionSelectOption]>;
|
| Snippet<[opt: ActionSelectOption]>;
|
||||||
title: string | Snippet<[opt: ActionSelectOption]>;
|
title: string | Snippet<[opt: ActionSelectOption]>;
|
||||||
|
disabled?: boolean;
|
||||||
onchoose?: (opt: ActionSelectOption) => void;
|
onchoose?: (opt: ActionSelectOption) => void;
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
@@ -41,6 +42,7 @@
|
|||||||
const select = new Select<ActionSelectOption>({
|
const select = new Select<ActionSelectOption>({
|
||||||
value: () => value,
|
value: () => value,
|
||||||
onValueChange: (val) => {
|
onValueChange: (val) => {
|
||||||
|
if (val?.disabled) return;
|
||||||
val?.onchoose?.(val);
|
val?.onchoose?.(val);
|
||||||
if (!stateless) {
|
if (!stateless) {
|
||||||
value = val;
|
value = val;
|
||||||
@@ -79,7 +81,9 @@
|
|||||||
<button
|
<button
|
||||||
class={[
|
class={[
|
||||||
'flex w-full items-center gap-3 rounded px-5 py-2 text-base font-medium transition-colors',
|
'flex w-full items-center gap-3 rounded px-5 py-2 text-base font-medium transition-colors',
|
||||||
stateless
|
option.disabled
|
||||||
|
? ['cursor-not-allowed opacity-50']
|
||||||
|
: stateless
|
||||||
? [select.highlighted?.title === option.title && 'bg-sui-text-100', 'cursor-pointer']
|
? [select.highlighted?.title === option.title && 'bg-sui-text-100', 'cursor-pointer']
|
||||||
: [
|
: [
|
||||||
select.highlighted?.title === option.title &&
|
select.highlighted?.title === option.title &&
|
||||||
|
|||||||
@@ -58,7 +58,12 @@
|
|||||||
class="basis-1/2"
|
class="basis-1/2"
|
||||||
stateless
|
stateless
|
||||||
label="Stateless Action"
|
label="Stateless Action"
|
||||||
options={[{ title: 'Yeet' }, { title: 'Yote' }, { title: 'Yote and Yeet' }]}
|
options={[
|
||||||
|
{ title: 'Yeet' },
|
||||||
|
{ title: 'Yote' },
|
||||||
|
{ title: 'Yote and Yeet' },
|
||||||
|
{ title: 'Disabled Action', disabled: true }
|
||||||
|
]}
|
||||||
/>
|
/>
|
||||||
<ActionSelect
|
<ActionSelect
|
||||||
class="basis-1/2"
|
class="basis-1/2"
|
||||||
@@ -66,7 +71,12 @@
|
|||||||
value={{ title: 'Initial Action', onchoose: (value) => console.log('Chosen:', value) }}
|
value={{ title: 'Initial Action', onchoose: (value) => console.log('Chosen:', value) }}
|
||||||
options={[
|
options={[
|
||||||
{ title: 'Action 1', onchoose: (value) => console.log('Action 1 chosen:', value) },
|
{ title: 'Action 1', onchoose: (value) => console.log('Action 1 chosen:', value) },
|
||||||
{ title: 'Action 2', onchoose: (value) => console.log('Action 2 chosen:', value) }
|
{ title: 'Action 2', onchoose: (value) => console.log('Action 2 chosen:', value) },
|
||||||
|
{
|
||||||
|
title: 'Disabled Action',
|
||||||
|
disabled: true,
|
||||||
|
onchoose: (value) => console.log('Disabled action chosen:', value)
|
||||||
|
}
|
||||||
]}
|
]}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user