@teammodlr/ui-kit 2.1.49 → 2.1.52
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/components/avatar/Avatar.vue.d.ts +1 -1
- package/lib/components/badge/style/Badge.css.d.ts +2 -2
- package/lib/components/button/Button.vue.d.ts +5 -5
- package/lib/components/button/style/Button.css.d.ts +3 -3
- package/lib/components/checkbox/Checkbox.vue.d.ts +4 -4
- package/lib/components/collapse/Collapse.vue.d.ts +82 -0
- package/lib/components/collapse/CollapseItem.vue.d.ts +43 -0
- package/lib/components/collapse/CollapseItemContent.vue.d.ts +29 -0
- package/lib/components/collapse/interface.d.ts +9 -0
- package/lib/components/collapse/style/Collapse.css.d.ts +8 -0
- package/lib/components/collapse/style/index.d.ts +1 -0
- package/lib/components/configprovider/ConfigProvider.vue.d.ts +11 -11
- package/lib/components/confirm/ConfirmProvider.vue.d.ts +10 -10
- package/lib/components/dialog/Dialog.vue.d.ts +1 -1
- package/lib/components/dropdown/Dropdown.vue.d.ts +2 -2
- package/lib/components/dropdown/DropdownItem.vue.d.ts +3 -3
- package/lib/components/dropdown/style/Dropdown.css.d.ts +1 -1
- package/lib/components/index.d.ts +3 -0
- package/lib/components/input/Input.vue.d.ts +7 -7
- package/lib/components/link/Link.vue.d.ts +2 -2
- package/lib/components/messageprovider/Message.vue.d.ts +2 -2
- package/lib/components/messageprovider/MessageProvider.vue.d.ts +5 -5
- package/lib/components/messageprovider/style/Message.css.d.ts +1 -1
- package/lib/components/modal/Modal.vue.d.ts +2 -2
- package/lib/components/radio/Radio.vue.d.ts +7 -7
- package/lib/components/radiobutton/RadioButton.vue.d.ts +6 -6
- package/lib/components/renderer/renderer.d.ts +1 -1
- package/lib/components/select/Select.vue.d.ts +21 -20
- package/lib/components/switch/Switch.vue.d.ts +4 -4
- package/lib/components/tab/Tab.vue.d.ts +4 -6
- package/lib/components/tab/TabGroup.vue.d.ts +17 -3
- package/lib/components/tab/style/Tab.css.d.ts +7 -0
- package/lib/components/tab/style/index.d.ts +1 -0
- package/lib/components/table/Table.vue.d.ts +2 -2
- package/lib/components/textarea/Textarea.vue.d.ts +6 -6
- package/lib/components/tree/Tree.vue.d.ts +1 -1
- package/lib/composables/useInput.d.ts +1 -1
- package/lib/index.cjs.js +10 -13
- package/lib/index.es.js +3151 -2955
- package/lib/install.d.ts +1 -1
- package/lib/style.css +1 -1
- package/lib/styles/theme.css.d.ts +1 -1
- package/package.json +76 -89
- package/src/call.ts +34 -34
- package/src/components/avatar/examples/index.stories.ts +25 -25
- package/src/components/avatargroup/examples/index.stories.ts +19 -19
- package/src/components/badge/examples/index.stories.ts +19 -19
- package/src/components/breadcrumb/examples/index.stories.ts +16 -16
- package/src/components/button/examples/index.stories.ts +37 -37
- package/src/components/buttongroup/examples/index.stories.ts +17 -17
- package/src/components/checkbox/examples/index.stories.ts +16 -16
- package/src/components/collapse/Collapse.vue +143 -0
- package/src/components/collapse/CollapseItem.vue +123 -0
- package/src/components/collapse/CollapseItemContent.vue +58 -0
- package/src/components/collapse/examples/basic.vue +13 -0
- package/src/components/collapse/examples/index.stories.ts +18 -0
- package/src/components/collapse/examples/index.ts +1 -0
- package/src/components/collapse/interface.ts +38 -0
- package/src/components/collapse/style/Collapse.css.ts +87 -0
- package/src/components/collapse/style/index.ts +1 -0
- package/src/components/colorpicker/examples/index.stories.ts +12 -12
- package/src/components/configprovider/ConfigProvider.vue +38 -38
- package/src/components/confirm/ConfirmProvider.vue +82 -82
- package/src/components/confirm/examples/index.stories.ts +26 -26
- package/src/components/dialog/examples/index.stories.ts +14 -14
- package/src/components/dropdown/examples/index.stories.ts +26 -26
- package/src/components/form/examples/index.stories.ts +23 -23
- package/src/components/image/examples/index.stories.ts +10 -10
- package/src/components/index.ts +51 -48
- package/src/components/input/examples/index.stories.ts +26 -26
- package/src/components/link/examples/index.stories.ts +15 -15
- package/src/components/messageprovider/examples/index.stories.ts +26 -26
- package/src/components/modal/examples/index.stories.ts +16 -16
- package/src/components/pagination/examples/index.stories.ts +11 -11
- package/src/components/radio/examples/index.stories.ts +16 -16
- package/src/components/radiobuttongroup/examples/index.stories.ts +18 -18
- package/src/components/renderer/examlpes/index.stories.ts +14 -14
- package/src/components/select/Select.vue +755 -755
- package/src/components/select/examples/basic.vue +26 -26
- package/src/components/select/examples/index.stories.ts +16 -16
- package/src/components/select/types.ts +27 -27
- package/src/components/skeleton/examples/index.stories.ts +13 -13
- package/src/components/switch/examples/index.stories.ts +15 -15
- package/src/components/switch/style/Switch.css.ts +135 -135
- package/src/components/tab/Tab.vue +85 -98
- package/src/components/tab/TabGroup.vue +96 -90
- package/src/components/tab/examples/index.stories.ts +21 -10
- package/src/components/tab/style/Tab.css.ts +137 -0
- package/src/components/tab/style/index.ts +1 -0
- package/src/components/table/examples/index.stories.ts +17 -17
- package/src/components/tag/examples/index.stories.ts +16 -16
- package/src/components/textarea/examples/index.stories.ts +14 -14
- package/src/components/tooltip/examples/index.stories.ts +17 -17
- package/src/components/transfer/examples/index.stories.ts +12 -12
- package/src/components/tree/examples/index.stories.ts +12 -12
- package/src/components/virtualscroll/examples/index.stories.ts +11 -11
- package/src/composables/useCachedUid.ts +15 -15
- package/src/composables/useInput.ts +151 -151
- package/src/examples/cards/cards.stories.ts +9 -9
- package/src/examples/modal/modal.stories.ts +9 -9
- package/src/types/props.ts +21 -21
- package/src/utils/call.ts +34 -34
- package/src/utils/injection.ts +45 -45
- package/src/components/tab/Tab.css +0 -113
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import MBadge from '../Badge.vue';
|
|
2
|
-
|
|
3
|
-
import { MBadgeBasic } from './index';
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
variantArgType,
|
|
7
|
-
createStory,
|
|
8
|
-
sizeArgType
|
|
9
|
-
} from '../../../__storybook__';
|
|
10
|
-
|
|
11
|
-
export default {
|
|
12
|
-
component: MBadge,
|
|
13
|
-
title: 'Components/Badge',
|
|
14
|
-
argTypes: {
|
|
15
|
-
...variantArgType()
|
|
16
|
-
}
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
export const Basic = createStory(MBadgeBasic);
|
|
1
|
+
import MBadge from '../Badge.vue';
|
|
2
|
+
|
|
3
|
+
import { MBadgeBasic } from './index';
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
variantArgType,
|
|
7
|
+
createStory,
|
|
8
|
+
sizeArgType
|
|
9
|
+
} from '../../../__storybook__';
|
|
10
|
+
|
|
11
|
+
export default {
|
|
12
|
+
component: MBadge,
|
|
13
|
+
title: 'Components/Badge',
|
|
14
|
+
argTypes: {
|
|
15
|
+
...variantArgType()
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export const Basic = createStory(MBadgeBasic);
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import MBreadcrumb from '../Breadcrumb.vue';
|
|
2
|
-
import MBreadcrumbItem from '../BreadcrumbItem.vue';
|
|
3
|
-
|
|
4
|
-
import { MBreadcrumbBasic } from './index';
|
|
5
|
-
|
|
6
|
-
import { createStory } from '../../../__storybook__';
|
|
7
|
-
|
|
8
|
-
export default {
|
|
9
|
-
component: MBreadcrumb,
|
|
10
|
-
subcomponents: {
|
|
11
|
-
MBreadcrumbItem
|
|
12
|
-
},
|
|
13
|
-
title: 'Components/Breadcrumb'
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
export const Basic = createStory(MBreadcrumbBasic);
|
|
1
|
+
import MBreadcrumb from '../Breadcrumb.vue';
|
|
2
|
+
import MBreadcrumbItem from '../BreadcrumbItem.vue';
|
|
3
|
+
|
|
4
|
+
import { MBreadcrumbBasic } from './index';
|
|
5
|
+
|
|
6
|
+
import { createStory } from '../../../__storybook__';
|
|
7
|
+
|
|
8
|
+
export default {
|
|
9
|
+
component: MBreadcrumb,
|
|
10
|
+
subcomponents: {
|
|
11
|
+
MBreadcrumbItem
|
|
12
|
+
},
|
|
13
|
+
title: 'Components/Breadcrumb'
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export const Basic = createStory(MBreadcrumbBasic);
|
|
@@ -1,37 +1,37 @@
|
|
|
1
|
-
import MButton from '../Button.vue';
|
|
2
|
-
import {
|
|
3
|
-
MButtonBasic,
|
|
4
|
-
MButtonSize,
|
|
5
|
-
MButtonRounded,
|
|
6
|
-
MButtonVariant,
|
|
7
|
-
MButtonVariantSecondary,
|
|
8
|
-
MButtonDisabled,
|
|
9
|
-
MButtonIconLeft,
|
|
10
|
-
MButtonIcon,
|
|
11
|
-
MButtonLink
|
|
12
|
-
} from './index';
|
|
13
|
-
|
|
14
|
-
import {
|
|
15
|
-
variantArgType,
|
|
16
|
-
createStory,
|
|
17
|
-
sizeArgType
|
|
18
|
-
} from '../../../__storybook__';
|
|
19
|
-
|
|
20
|
-
export default {
|
|
21
|
-
component: MButton,
|
|
22
|
-
title: 'Components/Buttons/Button',
|
|
23
|
-
argTypes: {
|
|
24
|
-
...variantArgType(),
|
|
25
|
-
...sizeArgType()
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
export const Basic = createStory(MButtonBasic);
|
|
30
|
-
export const Size = createStory(MButtonSize);
|
|
31
|
-
export const Rounded = createStory(MButtonRounded);
|
|
32
|
-
export const Colors = createStory(MButtonVariant);
|
|
33
|
-
export const ColorsSecondary = createStory(MButtonVariantSecondary);
|
|
34
|
-
export const Disabled = createStory(MButtonDisabled);
|
|
35
|
-
export const IconLeft = createStory(MButtonIconLeft);
|
|
36
|
-
export const Icon = createStory(MButtonIcon);
|
|
37
|
-
export const Link = createStory(MButtonLink);
|
|
1
|
+
import MButton from '../Button.vue';
|
|
2
|
+
import {
|
|
3
|
+
MButtonBasic,
|
|
4
|
+
MButtonSize,
|
|
5
|
+
MButtonRounded,
|
|
6
|
+
MButtonVariant,
|
|
7
|
+
MButtonVariantSecondary,
|
|
8
|
+
MButtonDisabled,
|
|
9
|
+
MButtonIconLeft,
|
|
10
|
+
MButtonIcon,
|
|
11
|
+
MButtonLink
|
|
12
|
+
} from './index';
|
|
13
|
+
|
|
14
|
+
import {
|
|
15
|
+
variantArgType,
|
|
16
|
+
createStory,
|
|
17
|
+
sizeArgType
|
|
18
|
+
} from '../../../__storybook__';
|
|
19
|
+
|
|
20
|
+
export default {
|
|
21
|
+
component: MButton,
|
|
22
|
+
title: 'Components/Buttons/Button',
|
|
23
|
+
argTypes: {
|
|
24
|
+
...variantArgType(),
|
|
25
|
+
...sizeArgType()
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export const Basic = createStory(MButtonBasic);
|
|
30
|
+
export const Size = createStory(MButtonSize);
|
|
31
|
+
export const Rounded = createStory(MButtonRounded);
|
|
32
|
+
export const Colors = createStory(MButtonVariant);
|
|
33
|
+
export const ColorsSecondary = createStory(MButtonVariantSecondary);
|
|
34
|
+
export const Disabled = createStory(MButtonDisabled);
|
|
35
|
+
export const IconLeft = createStory(MButtonIconLeft);
|
|
36
|
+
export const Icon = createStory(MButtonIcon);
|
|
37
|
+
export const Link = createStory(MButtonLink);
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import MButtonGroup from '../ButtonGroup.vue';
|
|
2
|
-
import MButton from '../../button/Button.vue';
|
|
3
|
-
import { MButtonGroupBasic, MButtonGroupIconGroup } from './index';
|
|
4
|
-
|
|
5
|
-
import { createStory, sizeArgType } from '../../../__storybook__';
|
|
6
|
-
|
|
7
|
-
export default {
|
|
8
|
-
component: MButtonGroup,
|
|
9
|
-
subcomponents: { MButton },
|
|
10
|
-
title: 'Components/Buttons/Group',
|
|
11
|
-
argTypes: {
|
|
12
|
-
...sizeArgType()
|
|
13
|
-
}
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
export const Basic = createStory(MButtonGroupBasic);
|
|
17
|
-
export const IconGroup = createStory(MButtonGroupIconGroup);
|
|
1
|
+
import MButtonGroup from '../ButtonGroup.vue';
|
|
2
|
+
import MButton from '../../button/Button.vue';
|
|
3
|
+
import { MButtonGroupBasic, MButtonGroupIconGroup } from './index';
|
|
4
|
+
|
|
5
|
+
import { createStory, sizeArgType } from '../../../__storybook__';
|
|
6
|
+
|
|
7
|
+
export default {
|
|
8
|
+
component: MButtonGroup,
|
|
9
|
+
subcomponents: { MButton },
|
|
10
|
+
title: 'Components/Buttons/Group',
|
|
11
|
+
argTypes: {
|
|
12
|
+
...sizeArgType()
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export const Basic = createStory(MButtonGroupBasic);
|
|
17
|
+
export const IconGroup = createStory(MButtonGroupIconGroup);
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import MCheckbox from '../Checkbox.vue';
|
|
2
|
-
import { MCheckboxBasic, MCheckboxSlot } from './index';
|
|
3
|
-
|
|
4
|
-
import { createStory, sizeArgType, colorArgType } from '../../../__storybook__';
|
|
5
|
-
|
|
6
|
-
export default {
|
|
7
|
-
component: MCheckbox,
|
|
8
|
-
title: 'Components/Checkbox',
|
|
9
|
-
argTypes: {
|
|
10
|
-
...sizeArgType(),
|
|
11
|
-
...colorArgType()
|
|
12
|
-
}
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
export const Basic = createStory(MCheckboxBasic);
|
|
16
|
-
export const Slot = createStory(MCheckboxSlot);
|
|
1
|
+
import MCheckbox from '../Checkbox.vue';
|
|
2
|
+
import { MCheckboxBasic, MCheckboxSlot } from './index';
|
|
3
|
+
|
|
4
|
+
import { createStory, sizeArgType, colorArgType } from '../../../__storybook__';
|
|
5
|
+
|
|
6
|
+
export default {
|
|
7
|
+
component: MCheckbox,
|
|
8
|
+
title: 'Components/Checkbox',
|
|
9
|
+
argTypes: {
|
|
10
|
+
...sizeArgType(),
|
|
11
|
+
...colorArgType()
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export const Basic = createStory(MCheckboxBasic);
|
|
16
|
+
export const Slot = createStory(MCheckboxSlot);
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { computed, defineComponent, provide, ref, type ExtractPropTypes, type ExtractPublicPropTypes, type InjectionKey, type PropType, type Ref, type Slots } from 'vue';
|
|
3
|
+
import { active } from '../pagination/style';
|
|
4
|
+
import { merge } from 'treemate/lib/utils';
|
|
5
|
+
import { call, type MaybeArray } from '../../call';
|
|
6
|
+
import type { HeaderClickInfo, OnItemHeaderClick, OnItemHeaderClickImpl, OnUpdateExpandedNames, OnUpdateExpandedNamesImpl } from './interface';
|
|
7
|
+
import { useMergedState } from 'vooks'
|
|
8
|
+
|
|
9
|
+
export const collapseProps = {
|
|
10
|
+
accordion: {
|
|
11
|
+
type: Boolean,
|
|
12
|
+
default: false
|
|
13
|
+
},
|
|
14
|
+
displayDirective: {
|
|
15
|
+
type: String as PropType<'if' | 'show'>,
|
|
16
|
+
default: 'if'
|
|
17
|
+
},
|
|
18
|
+
arrowPlacement: {
|
|
19
|
+
type: String as PropType<'left' | 'right'>,
|
|
20
|
+
default: 'left'
|
|
21
|
+
},
|
|
22
|
+
defaultExpandedNames: {
|
|
23
|
+
type: [Array, String] as PropType<
|
|
24
|
+
string | number | Array<string | number> | null
|
|
25
|
+
>,
|
|
26
|
+
default: null
|
|
27
|
+
},
|
|
28
|
+
expandedNames: [Array, String] as PropType<
|
|
29
|
+
string | number | Array<string | number> | null
|
|
30
|
+
>,
|
|
31
|
+
onItemHeaderClick: [Function, Array] as PropType<
|
|
32
|
+
MaybeArray<OnItemHeaderClick>
|
|
33
|
+
>,
|
|
34
|
+
'onUpdate:expandedNames': [Function, Array] as PropType<
|
|
35
|
+
MaybeArray<OnUpdateExpandedNames>
|
|
36
|
+
>,
|
|
37
|
+
onUpdateExpandedNames: [Function, Array] as PropType<
|
|
38
|
+
MaybeArray<OnUpdateExpandedNames>
|
|
39
|
+
>,
|
|
40
|
+
} as const;
|
|
41
|
+
|
|
42
|
+
export type CollapseProps = ExtractPublicPropTypes<typeof collapseProps>;
|
|
43
|
+
|
|
44
|
+
export interface CollapseInjection {
|
|
45
|
+
props: ExtractPropTypes<typeof collapseProps>,
|
|
46
|
+
expandedNamesRef: Ref<string | number | Array<string | number> | null>,
|
|
47
|
+
slots: Slots,
|
|
48
|
+
toggleItem: (
|
|
49
|
+
collapse: boolean,
|
|
50
|
+
name: string | number,
|
|
51
|
+
event: MouseEvent
|
|
52
|
+
) => void
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export const collapseInjectionKey: InjectionKey<CollapseInjection> = Symbol('collapse');
|
|
56
|
+
export default defineComponent({
|
|
57
|
+
name: 'Collapse',
|
|
58
|
+
props: collapseProps,
|
|
59
|
+
setup(props, { slots }) {
|
|
60
|
+
const uncontrolledExpandedNamesRef = ref<
|
|
61
|
+
string | number | Array<string | number> | null
|
|
62
|
+
>(props.defaultExpandedNames)
|
|
63
|
+
const controlledExpandedNamesRef = computed(() => props.expandedNames)
|
|
64
|
+
const mergedExpandedNamesRef = useMergedState(
|
|
65
|
+
controlledExpandedNamesRef,
|
|
66
|
+
uncontrolledExpandedNamesRef
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
function doUpdateExpandedNames(
|
|
70
|
+
names: Array<string | number> | string | number
|
|
71
|
+
): void {
|
|
72
|
+
const {
|
|
73
|
+
onUpdateExpandedNames
|
|
74
|
+
} = props;
|
|
75
|
+
|
|
76
|
+
if (onUpdateExpandedNames) {
|
|
77
|
+
call(onUpdateExpandedNames as OnUpdateExpandedNamesImpl, names)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
uncontrolledExpandedNamesRef.value = names;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function doItemHeaderClick<T extends string | number>(
|
|
84
|
+
info: HeaderClickInfo<T>
|
|
85
|
+
): void {
|
|
86
|
+
const { onItemHeaderClick } = props
|
|
87
|
+
if (onItemHeaderClick) {
|
|
88
|
+
call(onItemHeaderClick as OnItemHeaderClickImpl, info)
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function toggleItem(
|
|
93
|
+
collapse: boolean,
|
|
94
|
+
name: string | number,
|
|
95
|
+
event: MouseEvent
|
|
96
|
+
): void {
|
|
97
|
+
const { accordion } = props
|
|
98
|
+
const { value: expandedNames } = mergedExpandedNamesRef
|
|
99
|
+
if (accordion) {
|
|
100
|
+
if (collapse) {
|
|
101
|
+
doUpdateExpandedNames([name])
|
|
102
|
+
doItemHeaderClick({ name, expanded: true, event })
|
|
103
|
+
} else {
|
|
104
|
+
doUpdateExpandedNames([])
|
|
105
|
+
doItemHeaderClick({ name, expanded: false, event })
|
|
106
|
+
}
|
|
107
|
+
} else {
|
|
108
|
+
if (!Array.isArray(expandedNames)) {
|
|
109
|
+
doUpdateExpandedNames([name])
|
|
110
|
+
doItemHeaderClick({ name, expanded: true, event })
|
|
111
|
+
} else {
|
|
112
|
+
const activeNames = expandedNames.slice()
|
|
113
|
+
const index = activeNames.findIndex(
|
|
114
|
+
(activeName) => name === activeName
|
|
115
|
+
)
|
|
116
|
+
if (~index) {
|
|
117
|
+
activeNames.splice(index, 1)
|
|
118
|
+
doUpdateExpandedNames(activeNames)
|
|
119
|
+
doItemHeaderClick({ name, expanded: false, event })
|
|
120
|
+
} else {
|
|
121
|
+
activeNames.push(name)
|
|
122
|
+
doUpdateExpandedNames(activeNames)
|
|
123
|
+
doItemHeaderClick({ name, expanded: true, event })
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
provide(collapseInjectionKey, {
|
|
130
|
+
props,
|
|
131
|
+
expandedNamesRef: mergedExpandedNamesRef,
|
|
132
|
+
slots,
|
|
133
|
+
toggleItem
|
|
134
|
+
})
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
</script>
|
|
138
|
+
|
|
139
|
+
<template>
|
|
140
|
+
<div class="collapse">
|
|
141
|
+
<slot />
|
|
142
|
+
</div>
|
|
143
|
+
</template>
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { useMemo } from 'vooks';
|
|
3
|
+
import { computed, defineComponent, inject, toRef } from 'vue'
|
|
4
|
+
import type { ExtractPublicPropTypes, PropType } from 'vue';
|
|
5
|
+
import { collapseInjectionKey } from './Collapse.vue';
|
|
6
|
+
import MCollapseItemContent from './CollapseItemContent.vue';
|
|
7
|
+
import * as style from './style';
|
|
8
|
+
export const collapseItemProps = {
|
|
9
|
+
title: String,
|
|
10
|
+
name: [String, Number] as PropType<string | number>,
|
|
11
|
+
disabled: Boolean,
|
|
12
|
+
displayDirective: String as PropType<'if' | 'show'>,
|
|
13
|
+
} as const
|
|
14
|
+
|
|
15
|
+
export type CollapseItemProps = ExtractPublicPropTypes<typeof collapseItemProps>
|
|
16
|
+
|
|
17
|
+
export default defineComponent({
|
|
18
|
+
name: 'CollapseItem',
|
|
19
|
+
props: collapseItemProps,
|
|
20
|
+
setup(props) {
|
|
21
|
+
const randomName = Math.random().toString(36).substring(7);
|
|
22
|
+
const mergedNameRef = useMemo(() => {
|
|
23
|
+
return props.name ?? randomName;
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
const collapse = inject(collapseInjectionKey);
|
|
27
|
+
if (!collapse) {
|
|
28
|
+
throw new Error('<MCollapseItem> must be placed inside <MCollapse>.')
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const {
|
|
32
|
+
expandedNamesRef,
|
|
33
|
+
props: collapseProps,
|
|
34
|
+
slots: collapseSlots,
|
|
35
|
+
} = collapse;
|
|
36
|
+
|
|
37
|
+
const collapsedRef = computed<boolean>(() => {
|
|
38
|
+
const { value: expandedNames } = expandedNamesRef
|
|
39
|
+
if (Array.isArray(expandedNames)) {
|
|
40
|
+
const { value: name } = mergedNameRef
|
|
41
|
+
return !~expandedNames.findIndex(
|
|
42
|
+
(expandedName) => expandedName === name
|
|
43
|
+
)
|
|
44
|
+
} else if (expandedNames) {
|
|
45
|
+
const { value: name } = mergedNameRef
|
|
46
|
+
return name !== expandedNames
|
|
47
|
+
}
|
|
48
|
+
return true
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
const computedContentClasses = computed(() => {
|
|
52
|
+
return {
|
|
53
|
+
[style.collapseItem]: true
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
const computedHeaderClasses = computed(() => {
|
|
58
|
+
return {
|
|
59
|
+
[style.collapseItemHeader]: true
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
const computedHeaderMainClasses = computed(() => {
|
|
64
|
+
return {
|
|
65
|
+
[style.collapseItemHeaderMain]: true
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
const computedIconClasses = computed(() => {
|
|
70
|
+
return {
|
|
71
|
+
[style.collapseItemHeaderArrow]: true,
|
|
72
|
+
[style.collapseItemHeaderArrowActive]: !collapsedRef.value
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
return {
|
|
77
|
+
computedContentClasses,
|
|
78
|
+
computedHeaderClasses,
|
|
79
|
+
computedHeaderMainClasses,
|
|
80
|
+
computedIconClasses,
|
|
81
|
+
collapseSlots,
|
|
82
|
+
randomName,
|
|
83
|
+
collapsed: collapsedRef,
|
|
84
|
+
mergedDisplayDirective: computed<'if' | 'show'>(() => {
|
|
85
|
+
const { displayDirective } = props;
|
|
86
|
+
if (displayDirective) {
|
|
87
|
+
return displayDirective;
|
|
88
|
+
} else {
|
|
89
|
+
return collapseProps.displayDirective;
|
|
90
|
+
}
|
|
91
|
+
}),
|
|
92
|
+
arrowPlacement: computed<'left' | 'right'>(() => {
|
|
93
|
+
return collapseProps.arrowPlacement;
|
|
94
|
+
}),
|
|
95
|
+
handleClick(e: MouseEvent) {
|
|
96
|
+
if (collapse && !props.disabled) {
|
|
97
|
+
collapse.toggleItem(collapsedRef.value, mergedNameRef.value, e)
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
</script>
|
|
104
|
+
|
|
105
|
+
<template>
|
|
106
|
+
<div :class="computedContentClasses">
|
|
107
|
+
<div @click="handleClick" :class="computedHeaderClasses">
|
|
108
|
+
<div :class="computedHeaderMainClasses">
|
|
109
|
+
<svg :class="computedIconClasses" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none"
|
|
110
|
+
stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"
|
|
111
|
+
class="lucide lucide-chevron-right">
|
|
112
|
+
<path d="m9 18 6-6-6-6" />
|
|
113
|
+
</svg>
|
|
114
|
+
<slot name="header">
|
|
115
|
+
{{ title }}
|
|
116
|
+
</slot>
|
|
117
|
+
</div>
|
|
118
|
+
</div>
|
|
119
|
+
<MCollapseItemContent :displayDirective="mergedDisplayDirective" :show="!collapsed">
|
|
120
|
+
<slot />
|
|
121
|
+
</MCollapseItemContent>
|
|
122
|
+
</div>
|
|
123
|
+
</template>
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { computed, defineComponent, ref, toRef, type PropType } from 'vue'
|
|
3
|
+
import { useFalseUntilTruthy } from 'vooks'
|
|
4
|
+
import { collapseItemContentWrapper, collapseItemContentInner } from './style'
|
|
5
|
+
export default defineComponent({
|
|
6
|
+
name: 'CollapseItemContent',
|
|
7
|
+
props: {
|
|
8
|
+
displayDirective: {
|
|
9
|
+
type: String as PropType<'if' | 'show'>,
|
|
10
|
+
required: true
|
|
11
|
+
},
|
|
12
|
+
show: Boolean
|
|
13
|
+
},
|
|
14
|
+
setup(props, { slots }) {
|
|
15
|
+
const onceTrueRef = useFalseUntilTruthy(toRef(props, 'show'))
|
|
16
|
+
const useVShow = ref(props.displayDirective === 'show' && onceTrueRef.value)
|
|
17
|
+
|
|
18
|
+
const wrapperClassesComputed = computed(() => {
|
|
19
|
+
return {
|
|
20
|
+
[collapseItemContentWrapper]: true
|
|
21
|
+
}
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
const innerClassesComputed = computed(() => {
|
|
25
|
+
return {
|
|
26
|
+
[collapseItemContentInner]: true
|
|
27
|
+
}
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
return {
|
|
31
|
+
onceTrue: onceTrueRef,
|
|
32
|
+
useVShow,
|
|
33
|
+
slots,
|
|
34
|
+
wrapperClassesComputed,
|
|
35
|
+
innerClassesComputed
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
</script>
|
|
40
|
+
|
|
41
|
+
<template>
|
|
42
|
+
<div>
|
|
43
|
+
<div v-if="displayDirective === 'if' ? show : onceTrue">
|
|
44
|
+
<div :class="wrapperClassesComputed">
|
|
45
|
+
<div :class="innerClassesComputed">
|
|
46
|
+
<slot />
|
|
47
|
+
</div>
|
|
48
|
+
</div>
|
|
49
|
+
</div>
|
|
50
|
+
<div v-show="displayDirective === 'show' && onceTrue" v-if="!show">
|
|
51
|
+
<div :class="wrapperClassesComputed">
|
|
52
|
+
<div :class="innerClassesComputed">
|
|
53
|
+
<slot />
|
|
54
|
+
</div>
|
|
55
|
+
</div>
|
|
56
|
+
</div>
|
|
57
|
+
</div>
|
|
58
|
+
</template>
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<m-collapse :default-expanded-names="['1', '2']">
|
|
3
|
+
<m-collapse-item title="Ben is gay" name="1">
|
|
4
|
+
<div>yrs</div>
|
|
5
|
+
</m-collapse-item>
|
|
6
|
+
<m-collapse-item title="right" name="2">
|
|
7
|
+
<div>nice</div>
|
|
8
|
+
</m-collapse-item>
|
|
9
|
+
<m-collapse-item title="right" name="3">
|
|
10
|
+
<div>very good</div>
|
|
11
|
+
</m-collapse-item>
|
|
12
|
+
</m-collapse>
|
|
13
|
+
</template>
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/vue3';
|
|
2
|
+
import MCollapse from '../Collapse.vue';
|
|
3
|
+
import MCollapseItem from '../CollapseItem.vue';
|
|
4
|
+
import { MCollapseBasic } from './index';
|
|
5
|
+
import { createStory, sizeArgType } from '../../../__storybook__';
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
const meta: Meta<typeof MCollapse> = {
|
|
9
|
+
title: 'Components/Collapse',
|
|
10
|
+
component: MCollapse,
|
|
11
|
+
subcomponents: { MCollapse },
|
|
12
|
+
argTypes: {
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export default meta;
|
|
17
|
+
type Story = StoryObj<typeof MCollapse>;
|
|
18
|
+
export const Default = createStory(MCollapseBasic) as Story;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as MCollapseBasic } from './basic.vue';
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export type OnUpdateExpandedNames = <
|
|
2
|
+
T extends string[] &
|
|
3
|
+
number[] &
|
|
4
|
+
Array<string | number> &
|
|
5
|
+
(string | number | null) &
|
|
6
|
+
(string | null) &
|
|
7
|
+
(number | null)
|
|
8
|
+
>(
|
|
9
|
+
value: T
|
|
10
|
+
) => void
|
|
11
|
+
|
|
12
|
+
export type OnUpdateExpandedNamesImpl = <
|
|
13
|
+
T extends
|
|
14
|
+
| string[]
|
|
15
|
+
| number[]
|
|
16
|
+
| Array<string | number>
|
|
17
|
+
| (string | number | null)
|
|
18
|
+
| (string | null)
|
|
19
|
+
| (number | null)
|
|
20
|
+
>(
|
|
21
|
+
value: T
|
|
22
|
+
) => void
|
|
23
|
+
|
|
24
|
+
export type OnItemHeaderClick = <T extends string & number & (string | number) >(
|
|
25
|
+
info: HeaderClickInfo<T>
|
|
26
|
+
) => void
|
|
27
|
+
|
|
28
|
+
export type OnItemHeaderClickImpl = <
|
|
29
|
+
T extends string | number | (string | number)
|
|
30
|
+
>(
|
|
31
|
+
info: HeaderClickInfo<T>
|
|
32
|
+
) => void
|
|
33
|
+
|
|
34
|
+
export interface HeaderClickInfo<T> {
|
|
35
|
+
name: T
|
|
36
|
+
expanded: boolean
|
|
37
|
+
event: MouseEvent
|
|
38
|
+
}
|