Skip to content

Commit a12bb48

Browse files
committed
feat(packages): ui: command support size
1 parent 472e449 commit a12bb48

16 files changed

+190
-118
lines changed

packages/ui/src/components/command/command-empty.vue

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@ defineOptions({
77
name: 'SCommandEmpty'
88
});
99
10-
const { class: cls } = defineProps<CommandEmptyProps>();
10+
const { class: cls, size } = defineProps<CommandEmptyProps>();
1111
12-
const { empty } = commandVariants();
12+
const mergedCls = computed(() => {
13+
const { empty } = commandVariants({ size });
1314
14-
const mergedCls = computed(() => cn(empty(), cls));
15+
return cn(empty(), cls);
16+
});
1517
</script>
1618

1719
<template>

packages/ui/src/components/command/command-group-label.vue

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@ defineOptions({
88
name: 'SCommandGroupLabel'
99
});
1010
11-
const { class: cls } = defineProps<CommandGroupLabelProps>();
11+
const { class: cls, size } = defineProps<CommandGroupLabelProps>();
1212
13-
const { groupLabel } = commandVariants();
13+
const mergedCls = computed(() => {
14+
const { groupLabel } = commandVariants({ size });
1415
15-
const mergedCls = computed(() => cn(groupLabel(), cls));
16+
return cn(groupLabel(), cls);
17+
});
1618
</script>
1719

1820
<template>

packages/ui/src/components/command/command-input-icon.vue

Lines changed: 0 additions & 20 deletions
This file was deleted.

packages/ui/src/components/command/command-input-wrapper.vue

Lines changed: 0 additions & 22 deletions
This file was deleted.

packages/ui/src/components/command/command-input.vue

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,37 @@
22
import { computed } from 'vue';
33
import { ListboxFilter, useForwardPropsEmits } from '@soybean-ui/primitives';
44
import { cn, commandVariants } from '@soybean-ui/variants';
5+
import { Search } from 'lucide-vue-next';
56
import type { CommandInputEmits, CommandInputProps } from './types';
67
78
defineOptions({
8-
name: 'SCommandInput'
9+
name: 'SCommandInput',
10+
inheritAttrs: false
911
});
1012
11-
const { class: cls, autoFocus: _, ...delegatedProps } = defineProps<CommandInputProps>();
13+
const { class: cls, size, wrapperClass, iconClass, autoFocus: _, ...delegatedProps } = defineProps<CommandInputProps>();
1214
1315
const emit = defineEmits<CommandInputEmits>();
1416
1517
const forwarded = useForwardPropsEmits(delegatedProps, emit);
1618
17-
const { input } = commandVariants();
19+
const mergedCls = computed(() => {
20+
const { input, inputWrapper, inputIcon } = commandVariants({ size });
1821
19-
const mergedCls = computed(() => cn(input(), cls));
22+
return {
23+
cls: cn(input(), cls),
24+
wrapper: cn(inputWrapper(), wrapperClass),
25+
icon: cn(inputIcon(), iconClass)
26+
};
27+
});
2028
</script>
2129

2230
<template>
23-
<ListboxFilter v-bind="forwarded" :class="mergedCls" auto-focus />
31+
<div :class="mergedCls.wrapper">
32+
<slot name="leading">
33+
<Search :class="mergedCls.icon" />
34+
</slot>
35+
<ListboxFilter v-bind="forwarded" :class="mergedCls.cls" auto-focus />
36+
<slot name="trailing" />
37+
</div>
2438
</template>

packages/ui/src/components/command/command-item.vue

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,17 @@ defineOptions({
99
name: 'SCommandItem'
1010
});
1111
12-
const { class: cls, ...delegatedProps } = defineProps<CommandItemProps<T>>();
12+
const { class: cls, size, ...delegatedProps } = defineProps<CommandItemProps<T>>();
1313
1414
const emit = defineEmits<CommandItemEmits<T>>();
1515
1616
const forwardedProps = useForwardPropsEmits(delegatedProps, emit);
1717
18-
const { item } = commandVariants();
18+
const mergedCls = computed(() => {
19+
const { item } = commandVariants({ size });
1920
20-
const mergedCls = computed(() => cn(item(), cls));
21+
return cn(item(), cls);
22+
});
2123
</script>
2224

2325
<template>

packages/ui/src/components/command/command-list.vue

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@ defineOptions({
88
name: 'SCommandList'
99
});
1010
11-
const { class: cls, ...delegatedProps } = defineProps<CommandListProps>();
11+
const { class: cls, size, ...delegatedProps } = defineProps<CommandListProps>();
1212
1313
const forwarded = useForwardProps(delegatedProps);
1414
15-
const { list } = commandVariants();
15+
const mergedCls = computed(() => {
16+
const { list } = commandVariants({ size });
1617
17-
const mergedCls = computed(() => cn(list(), cls));
18+
return cn(list(), cls);
19+
});
1820
</script>
1921

2022
<template>

packages/ui/src/components/command/command-option.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ defineSlots<Slots>();
3737
<slot :item="opt" />
3838
</SCommandSingleOption>
3939
</SCommandGroup>
40-
<SCommandSeparator v-if="item.separator" :class="ui?.separator" />
40+
<SCommandSeparator v-if="item.separator" :class="ui?.separator" :size="size" />
4141
</template>
4242
<SCommandSingleOption v-else :size="size" :item="item" :ui="ui" @select="emit('select', item, $event)">
4343
<slot :item="item" />
Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
<script setup lang="ts">
22
import { computed } from 'vue';
3-
import { Primitive } from '@soybean-ui/primitives';
43
import { cn, commandVariants } from '@soybean-ui/variants';
54
import type { CommandSeparatorProps } from './types';
65
76
defineOptions({
87
name: 'SCommandSeparator'
98
});
109
11-
const { class: cls } = defineProps<CommandSeparatorProps>();
10+
const { class: cls, size } = defineProps<CommandSeparatorProps>();
1211
13-
const { separator } = commandVariants();
12+
const mergedCls = computed(() => {
13+
const { separator } = commandVariants({ size });
1414
15-
const mergedCls = computed(() => cn(separator(), cls));
15+
return cn(separator(), cls);
16+
});
1617
</script>
1718

1819
<template>
19-
<Primitive :class="mergedCls" />
20+
<div :class="mergedCls"></div>
2021
</template>

packages/ui/src/components/command/command-shortcut.vue

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,9 @@ defineOptions({
1111
1212
const { class: cls, size, value } = defineProps<CommandShortcutProps<T>>();
1313
14-
const mergedCls = computed(() => {
15-
const { shortcut } = commandVariants({ size });
14+
const { shortcut } = commandVariants();
1615
17-
return cn(shortcut(), cls);
18-
});
16+
const mergedCls = computed(() => cn(shortcut(), cls));
1917
</script>
2018

2119
<template>

packages/ui/src/components/command/command-single-option.vue

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,18 @@ const emit = defineEmits<CommandSingleOptionEmits<T>>();
1616
</script>
1717

1818
<template>
19-
<SCommandItem :class="ui?.item" :value="item.value" :disabled="item.disabled" @select="emit('select', $event)">
19+
<SCommandItem
20+
:class="ui?.item"
21+
:size="size"
22+
:value="item.value"
23+
:disabled="item.disabled"
24+
@select="emit('select', $event)"
25+
>
2026
<slot name="item">
2127
<component :is="item.icon" v-if="item.icon" :class="ui?.itemIcon" />
2228
<span>{{ item.label }}</span>
23-
<SCommandShortcut v-if="item.shortcut" :class="ui?.shortcut" :value="item.shortcut" />
29+
<SCommandShortcut v-if="item.shortcut" :class="ui?.shortcut" :size="size" :value="item.shortcut" />
2430
</slot>
2531
</SCommandItem>
26-
<SCommandSeparator v-if="item.separator" :class="ui?.separator" />
32+
<SCommandSeparator v-if="item.separator" :class="ui?.separator" :size="size" />
2733
</template>

packages/ui/src/components/command/command.vue

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ import { useCombinedPropsEmits, useOmitEmitAsProps, useOmitForwardProps } from '
77
import type { AcceptableValue } from '@soybean-ui/primitives';
88
import { defu } from 'defu';
99
import SCommandRoot from './command-root.vue';
10-
import SCommandInputWrapper from './command-input-wrapper.vue';
1110
import SCommandInput from './command-input.vue';
12-
import SCommandInputIcon from './command-input-icon.vue';
1311
import SCommandList from './command-list.vue';
1412
import SCommandEmpty from './command-empty.vue';
1513
import SCommandOption from './command-option.vue';
@@ -25,6 +23,8 @@ const props = defineProps<CommandProps<T>>();
2523
const emit = defineEmits<CommandEmits<T>>();
2624
2725
type Slots = {
26+
leading: () => any;
27+
trailing: () => any;
2828
empty: (props: { searchTerm: string }) => any;
2929
item: (props: { item: CommandOptionData<T> }) => any;
3030
};
@@ -67,17 +67,24 @@ const filteredItems = computed(() => {
6767

6868
<template>
6969
<SCommandRoot v-bind="forwardedRoot" :class="props.class || ui?.root">
70-
<SCommandInputWrapper :class="ui?.inputWrapper">
71-
<SCommandInputIcon :class="ui?.inputIcon" />
72-
<SCommandInput
73-
v-bind="inputProps"
74-
v-model="searchTerm"
75-
:class="ui?.input"
76-
@update:model-value="emit('update:searchTerm', $event)"
77-
/>
78-
</SCommandInputWrapper>
79-
<SCommandList :class="ui?.list">
80-
<SCommandEmpty v-if="!filteredItems.length && searchTerm" :class="ui?.empty">
70+
<SCommandInput
71+
v-bind="inputProps"
72+
v-model="searchTerm"
73+
:class="ui?.input"
74+
:wrapper-class="ui?.inputWrapper"
75+
:icon-class="ui?.inputIcon"
76+
:size="size"
77+
@update:model-value="emit('update:searchTerm', $event)"
78+
>
79+
<template #leading>
80+
<slot name="leading" />
81+
</template>
82+
<template #trailing>
83+
<slot name="trailing" />
84+
</template>
85+
</SCommandInput>
86+
<SCommandList :class="ui?.list" :size="size">
87+
<SCommandEmpty v-if="!filteredItems.length && searchTerm" :class="ui?.empty" :size="size">
8188
<slot name="empty" :search-term="searchTerm">
8289
{{ emptyLabel || `No result for "${searchTerm}"` }}
8390
</slot>

packages/ui/src/components/command/index.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import SCommandRoot from './command-root.vue';
2-
import SCommandInputWrapper from './command-input-wrapper.vue';
32
import SCommandInput from './command-input.vue';
4-
import SCommandInputIcon from './command-input-icon.vue';
53
import SCommandList from './command-list.vue';
64
import SCommandEmpty from './command-empty.vue';
75
import SCommandGroup from './command-group.vue';
@@ -14,9 +12,7 @@ import SCommandDialog from './command-dialog.vue';
1412

1513
export {
1614
SCommandRoot,
17-
SCommandInputWrapper,
1815
SCommandInput,
19-
SCommandInputIcon,
2016
SCommandList,
2117
SCommandEmpty,
2218
SCommandGroup,

packages/ui/src/components/command/types.ts

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,36 +25,49 @@ import type { InputProps } from '../input';
2525
import type { KeyboardKeyProps, KeyboardKeyValue } from '../keyboard-key';
2626

2727
// CommandRoot
28-
export interface CommandRootProps<T extends AcceptableValue = AcceptableValue> extends ListboxRootProps<T> {
29-
size?: ThemeSize;
30-
}
28+
export interface CommandRootProps<T extends AcceptableValue = AcceptableValue> extends ListboxRootProps<T> {}
3129
export type CommandRootEmits<T extends AcceptableValue = AcceptableValue> = ListboxRootEmits<T>;
3230

3331
// CommandInput
34-
export interface CommandInputWrapperProps extends ClassValueProp {}
35-
export interface CommandInputProps extends InputProps, ListboxFilterProps {}
32+
export interface CommandInputProps extends InputProps, ListboxFilterProps {
33+
size?: ThemeSize;
34+
wrapperClass?: ClassValue;
35+
iconClass?: ClassValue;
36+
}
3637
export type CommandInputEmits = ListboxFilterEmits;
37-
export interface CommandInputIconProps extends ClassValueProp {}
38+
export interface CommandInputIconProps extends ClassValueProp {
39+
size?: ThemeSize;
40+
}
3841

3942
// CommandEmpty
40-
export interface CommandEmptyProps extends ClassValueProp {}
43+
export interface CommandEmptyProps extends ClassValueProp {
44+
size?: ThemeSize;
45+
}
4146

4247
// CommandList
43-
export interface CommandListProps extends ListboxContentProps {}
48+
export interface CommandListProps extends ListboxContentProps {
49+
size?: ThemeSize;
50+
}
4451

4552
// CommandGroup
4653
export interface CommandGroupProps extends ListboxGroupProps {}
47-
export interface CommandGroupLabelProps extends ClassValueProp {}
54+
export interface CommandGroupLabelProps extends ClassValueProp {
55+
size?: ThemeSize;
56+
}
4857

4958
// CommandItem
50-
export interface CommandItemProps<T extends AcceptableValue = AcceptableValue> extends ListboxItemProps<T> {}
59+
export interface CommandItemProps<T extends AcceptableValue = AcceptableValue> extends ListboxItemProps<T> {
60+
size?: ThemeSize;
61+
}
5162
export type CommandItemEmits<T extends AcceptableValue = AcceptableValue> = ListboxItemEmits<T>;
5263

5364
// CommandItemIndicator
5465
export interface CommandItemIndicatorProps extends ListboxItemIndicatorProps {}
5566

5667
// CommandSeparator
57-
export interface CommandSeparatorProps extends ClassValueProp {}
68+
export interface CommandSeparatorProps extends ClassValueProp {
69+
size?: ThemeSize;
70+
}
5871

5972
// CommandDialog
6073
export interface CommandDialogProps
@@ -131,6 +144,7 @@ export type CommandUi = Partial<Record<CommandSlots, ClassValue>>;
131144

132145
// Command
133146
export interface CommandProps<T extends AcceptableValue = AcceptableValue> extends CommandRootProps<T> {
147+
size?: ThemeSize;
134148
items: (CommandOptionData<T> | CommandGroupOptionData<T>)[];
135149
ui?: CommandUi;
136150
fuseOptions?: UseFuseOptions<CommandSearchOptionData<T>>;

0 commit comments

Comments
 (0)