@chayns-components/core 5.0.0-beta.894 → 5.0.0-beta.895
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/cjs/components/select-button/SelectButton.js +8 -6
- package/lib/cjs/components/select-button/SelectButton.js.map +1 -1
- package/lib/esm/components/select-button/SelectButton.js +8 -6
- package/lib/esm/components/select-button/SelectButton.js.map +1 -1
- package/lib/types/components/select-button/SelectButton.d.ts +8 -0
- package/package.json +2 -2
|
@@ -19,6 +19,8 @@ const SelectButton = ({
|
|
|
19
19
|
selectedItemIds,
|
|
20
20
|
shouldAllowMultiSelect,
|
|
21
21
|
shouldShowButtonTextWithSelection,
|
|
22
|
+
maxDisplayedItems = 3,
|
|
23
|
+
additionalText = ', ##count## weitere',
|
|
22
24
|
shouldShowSearch,
|
|
23
25
|
selectAllText,
|
|
24
26
|
title
|
|
@@ -44,21 +46,21 @@ const SelectButton = ({
|
|
|
44
46
|
}
|
|
45
47
|
let addedCount = 0;
|
|
46
48
|
let newText = '';
|
|
47
|
-
const additionalCount = selectedItemIds.length -
|
|
49
|
+
const additionalCount = selectedItemIds.length - maxDisplayedItems;
|
|
48
50
|
list.forEach(({
|
|
49
51
|
text,
|
|
50
52
|
id
|
|
51
53
|
}) => {
|
|
52
|
-
if (
|
|
53
|
-
addedCount
|
|
54
|
+
if (addedCount < maxDisplayedItems && selectedItemIds !== null && selectedItemIds !== void 0 && selectedItemIds.includes(id)) {
|
|
55
|
+
addedCount++;
|
|
54
56
|
newText += newText.length === 0 ? `${text}` : `, ${text}`;
|
|
55
57
|
}
|
|
56
58
|
});
|
|
57
|
-
if (additionalCount
|
|
58
|
-
newText +=
|
|
59
|
+
if (additionalCount >= 1) {
|
|
60
|
+
newText += additionalText.replace('##count##', String(additionalCount));
|
|
59
61
|
}
|
|
60
62
|
return newText;
|
|
61
|
-
}, [buttonText, list, selectedItemIds, shouldShowButtonTextWithSelection]);
|
|
63
|
+
}, [additionalText, buttonText, list, maxDisplayedItems, selectedItemIds, shouldShowButtonTextWithSelection]);
|
|
62
64
|
const handleClick = () => {
|
|
63
65
|
void (0, _chaynsApi.createDialog)({
|
|
64
66
|
text: title ? `[h1]${title}[/h1]` : undefined,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SelectButton.js","names":["_chaynsApi","require","_react","_interopRequireWildcard","_Button","_interopRequireDefault","_SelectButton","e","__esModule","default","_getRequireWildcardCache","WeakMap","r","t","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","SelectButton","buttonText","isDisabled","list","onSelect","selectedItemIds","shouldAllowMultiSelect","shouldShowButtonTextWithSelection","shouldShowSearch","selectAllText","title","itemList","useMemo","items","forEach","text","id","isSelected","includes","push","name","internalButtonText","length","addedCount","newText","additionalCount","handleClick","createDialog","undefined","type","DialogType","SELECT","multiselect","quickfind","selectAllCheckbox","open","then","result","buttonType","map","Number","createElement","StyledSelectButton","onClick","isSecondary","shouldShowTextAsRobotoMedium","displayName","_default","exports"],"sources":["../../../../src/components/select-button/SelectButton.tsx"],"sourcesContent":["import { createDialog, DialogType, type DialogSelectListItemType } from 'chayns-api';\nimport React, { useMemo, type FC } from 'react';\nimport type { SelectButtonItem } from '../../types/selectButton';\nimport Button from '../button/Button';\nimport { StyledSelectButton } from './SelectButton.styles';\n\nexport type SelectButtonProps = {\n /**\n * The text that should be displayed inside the button.\n */\n buttonText: string;\n /**\n * Whether the button should be disabled.\n */\n isDisabled?: boolean;\n /**\n * A list of item that could be selected.\n */\n list: SelectButtonItem[];\n /**\n * Function to be executed after an item is selected.\n */\n onSelect?: (ids: number[]) => void;\n /**\n * If a string is given and `shouldAllowMultiSelect` is true, the dialog displays a checkbox to select all items at once.\n */\n selectAllText?: string;\n /**\n * The id of an item that should be preselected.\n */\n selectedItemIds?: number[];\n /**\n * Whether more than one item should be selectable.\n */\n shouldAllowMultiSelect?: boolean;\n /**\n * Whether the button text should be displayed also if items are selected.\n */\n shouldShowButtonTextWithSelection?: boolean;\n /**\n * Whether the search should be displayed inside the dialog.\n */\n shouldShowSearch?: boolean;\n /**\n * The title of the dialog.\n */\n title?: string;\n};\n\nconst SelectButton: FC<SelectButtonProps> = ({\n buttonText,\n isDisabled,\n list,\n onSelect,\n selectedItemIds,\n shouldAllowMultiSelect,\n shouldShowButtonTextWithSelection,\n shouldShowSearch,\n selectAllText,\n title,\n}) => {\n const itemList = useMemo(() => {\n const items: DialogSelectListItemType[] = [];\n\n list.forEach(({ text, id }) => {\n const isSelected = selectedItemIds ? selectedItemIds.includes(id) : false;\n\n items.push({\n name: text,\n id,\n isSelected,\n });\n });\n\n return items;\n }, [list, selectedItemIds]);\n\n const internalButtonText = useMemo(() => {\n if (shouldShowButtonTextWithSelection || !selectedItemIds || selectedItemIds.length === 0) {\n return buttonText;\n }\n\n let addedCount = 0;\n let newText = '';\n\n const additionalCount = selectedItemIds.length -
|
|
1
|
+
{"version":3,"file":"SelectButton.js","names":["_chaynsApi","require","_react","_interopRequireWildcard","_Button","_interopRequireDefault","_SelectButton","e","__esModule","default","_getRequireWildcardCache","WeakMap","r","t","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","SelectButton","buttonText","isDisabled","list","onSelect","selectedItemIds","shouldAllowMultiSelect","shouldShowButtonTextWithSelection","maxDisplayedItems","additionalText","shouldShowSearch","selectAllText","title","itemList","useMemo","items","forEach","text","id","isSelected","includes","push","name","internalButtonText","length","addedCount","newText","additionalCount","replace","String","handleClick","createDialog","undefined","type","DialogType","SELECT","multiselect","quickfind","selectAllCheckbox","open","then","result","buttonType","map","Number","createElement","StyledSelectButton","onClick","isSecondary","shouldShowTextAsRobotoMedium","displayName","_default","exports"],"sources":["../../../../src/components/select-button/SelectButton.tsx"],"sourcesContent":["import { createDialog, DialogType, type DialogSelectListItemType } from 'chayns-api';\nimport React, { useMemo, type FC } from 'react';\nimport type { SelectButtonItem } from '../../types/selectButton';\nimport Button from '../button/Button';\nimport { StyledSelectButton } from './SelectButton.styles';\n\nexport type SelectButtonProps = {\n /**\n * Text used when there are more selected items than maxDisplayedItems. '##count##' will be displayed with the additional count.\n */\n additionalText?: string;\n /**\n * The text that should be displayed inside the button.\n */\n buttonText: string;\n /**\n * Whether the button should be disabled.\n */\n isDisabled?: boolean;\n /**\n * A list of item that could be selected.\n */\n list: SelectButtonItem[];\n /**\n * The maximum number of items displayed in the button text.\n */\n maxDisplayedItems?: number;\n /**\n * Function to be executed after an item is selected.\n */\n onSelect?: (ids: number[]) => void;\n /**\n * If a string is given and `shouldAllowMultiSelect` is true, the dialog displays a checkbox to select all items at once.\n */\n selectAllText?: string;\n /**\n * The id of an item that should be preselected.\n */\n selectedItemIds?: number[];\n /**\n * Whether more than one item should be selectable.\n */\n shouldAllowMultiSelect?: boolean;\n /**\n * Whether the button text should be displayed also if items are selected.\n */\n shouldShowButtonTextWithSelection?: boolean;\n /**\n * Whether the search should be displayed inside the dialog.\n */\n shouldShowSearch?: boolean;\n /**\n * The title of the dialog.\n */\n title?: string;\n};\n\nconst SelectButton: FC<SelectButtonProps> = ({\n buttonText,\n isDisabled,\n list,\n onSelect,\n selectedItemIds,\n shouldAllowMultiSelect,\n shouldShowButtonTextWithSelection,\n maxDisplayedItems = 3,\n additionalText = ', ##count## weitere',\n shouldShowSearch,\n selectAllText,\n title,\n}) => {\n const itemList = useMemo(() => {\n const items: DialogSelectListItemType[] = [];\n\n list.forEach(({ text, id }) => {\n const isSelected = selectedItemIds ? selectedItemIds.includes(id) : false;\n\n items.push({\n name: text,\n id,\n isSelected,\n });\n });\n\n return items;\n }, [list, selectedItemIds]);\n\n const internalButtonText = useMemo(() => {\n if (shouldShowButtonTextWithSelection || !selectedItemIds || selectedItemIds.length === 0) {\n return buttonText;\n }\n\n let addedCount = 0;\n let newText = '';\n\n const additionalCount = selectedItemIds.length - maxDisplayedItems;\n\n list.forEach(({ text, id }) => {\n if (addedCount < maxDisplayedItems && selectedItemIds?.includes(id)) {\n addedCount++;\n newText += newText.length === 0 ? `${text}` : `, ${text}`;\n }\n });\n\n if (additionalCount >= 1) {\n newText += additionalText.replace('##count##', String(additionalCount));\n }\n\n return newText;\n }, [\n additionalText,\n buttonText,\n list,\n maxDisplayedItems,\n selectedItemIds,\n shouldShowButtonTextWithSelection,\n ]);\n\n const handleClick = () => {\n void createDialog({\n text: title ? `[h1]${title}[/h1]` : undefined,\n type: DialogType.SELECT,\n list: itemList,\n multiselect: shouldAllowMultiSelect,\n quickfind: shouldShowSearch,\n selectAllCheckbox: selectAllText,\n })\n .open()\n .then((result) => {\n // Ignore because there is no type\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n if (result && result.buttonType === 1 && typeof onSelect === 'function') {\n // Ignore because there is no type\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n onSelect((result.result as string[]).map(Number));\n }\n });\n };\n\n return (\n <StyledSelectButton>\n <Button\n onClick={handleClick}\n isDisabled={isDisabled}\n isSecondary\n shouldShowTextAsRobotoMedium={false}\n >\n {internalButtonText}\n </Button>\n </StyledSelectButton>\n );\n};\n\nSelectButton.displayName = 'SelectButton';\n\nexport default SelectButton;\n"],"mappings":";;;;;;AAAA,IAAAA,UAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAC,uBAAA,CAAAF,OAAA;AAEA,IAAAG,OAAA,GAAAC,sBAAA,CAAAJ,OAAA;AACA,IAAAK,aAAA,GAAAL,OAAA;AAA2D,SAAAI,uBAAAE,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAAA,SAAAG,yBAAAH,CAAA,6BAAAI,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAD,wBAAA,YAAAA,CAAAH,CAAA,WAAAA,CAAA,GAAAM,CAAA,GAAAD,CAAA,KAAAL,CAAA;AAAA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uB,WAAW,GAAGA,CAAA,KAAM;IACtB,KAAK,IAAAC,uBAAY,EAAC;MACdd,IAAI,EAAEL,KAAK,GAAG,OAAOA,KAAK,OAAO,GAAGoB,SAAS;MAC7CC,IAAI,EAAEC,qBAAU,CAACC,MAAM;MACvBhC,IAAI,EAAEU,QAAQ;MACduB,WAAW,EAAE9B,sBAAsB;MACnC+B,SAAS,EAAE3B,gBAAgB;MAC3B4B,iBAAiB,EAAE3B;IACvB,CAAC,CAAC,CACG4B,IAAI,CAAC,CAAC,CACNC,IAAI,CAAEC,MAAM,IAAK;MACd;MACA;MACA;MACA,IAAIA,MAAM,IAAIA,MAAM,CAACC,UAAU,KAAK,CAAC,IAAI,OAAOtC,QAAQ,KAAK,UAAU,EAAE;QACrE;QACA;QACA;QACAA,QAAQ,CAAEqC,MAAM,CAACA,MAAM,CAAcE,GAAG,CAACC,MAAM,CAAC,CAAC;MACrD;IACJ,CAAC,CAAC;EACV,CAAC;EAED,oBACIrE,MAAA,CAAAO,OAAA,CAAA+D,aAAA,CAAClE,aAAA,CAAAmE,kBAAkB,qBACfvE,MAAA,CAAAO,OAAA,CAAA+D,aAAA,CAACpE,OAAA,CAAAK,OAAM;IACHiE,OAAO,EAAEjB,WAAY;IACrB5B,UAAU,EAAEA,UAAW;IACvB8C,WAAW;IACXC,4BAA4B,EAAE;EAAM,GAEnC1B,kBACG,CACQ,CAAC;AAE7B,CAAC;AAEDvB,YAAY,CAACkD,WAAW,GAAG,cAAc;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAAtE,OAAA,GAE3BkB,YAAY","ignoreList":[]}
|
|
@@ -11,6 +11,8 @@ const SelectButton = _ref => {
|
|
|
11
11
|
selectedItemIds,
|
|
12
12
|
shouldAllowMultiSelect,
|
|
13
13
|
shouldShowButtonTextWithSelection,
|
|
14
|
+
maxDisplayedItems = 3,
|
|
15
|
+
additionalText = ', ##count## weitere',
|
|
14
16
|
shouldShowSearch,
|
|
15
17
|
selectAllText,
|
|
16
18
|
title
|
|
@@ -37,22 +39,22 @@ const SelectButton = _ref => {
|
|
|
37
39
|
}
|
|
38
40
|
let addedCount = 0;
|
|
39
41
|
let newText = '';
|
|
40
|
-
const additionalCount = selectedItemIds.length -
|
|
42
|
+
const additionalCount = selectedItemIds.length - maxDisplayedItems;
|
|
41
43
|
list.forEach(_ref3 => {
|
|
42
44
|
let {
|
|
43
45
|
text,
|
|
44
46
|
id
|
|
45
47
|
} = _ref3;
|
|
46
|
-
if (
|
|
47
|
-
addedCount
|
|
48
|
+
if (addedCount < maxDisplayedItems && selectedItemIds?.includes(id)) {
|
|
49
|
+
addedCount++;
|
|
48
50
|
newText += newText.length === 0 ? `${text}` : `, ${text}`;
|
|
49
51
|
}
|
|
50
52
|
});
|
|
51
|
-
if (additionalCount
|
|
52
|
-
newText +=
|
|
53
|
+
if (additionalCount >= 1) {
|
|
54
|
+
newText += additionalText.replace('##count##', String(additionalCount));
|
|
53
55
|
}
|
|
54
56
|
return newText;
|
|
55
|
-
}, [buttonText, list, selectedItemIds, shouldShowButtonTextWithSelection]);
|
|
57
|
+
}, [additionalText, buttonText, list, maxDisplayedItems, selectedItemIds, shouldShowButtonTextWithSelection]);
|
|
56
58
|
const handleClick = () => {
|
|
57
59
|
void createDialog({
|
|
58
60
|
text: title ? `[h1]${title}[/h1]` : undefined,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SelectButton.js","names":["createDialog","DialogType","React","useMemo","Button","StyledSelectButton","SelectButton","_ref","buttonText","isDisabled","list","onSelect","selectedItemIds","shouldAllowMultiSelect","shouldShowButtonTextWithSelection","shouldShowSearch","selectAllText","title","itemList","items","forEach","_ref2","text","id","isSelected","includes","push","name","internalButtonText","length","addedCount","newText","additionalCount","_ref3","handleClick","undefined","type","SELECT","multiselect","quickfind","selectAllCheckbox","open","then","result","buttonType","map","Number","createElement","onClick","isSecondary","shouldShowTextAsRobotoMedium","displayName"],"sources":["../../../../src/components/select-button/SelectButton.tsx"],"sourcesContent":["import { createDialog, DialogType, type DialogSelectListItemType } from 'chayns-api';\nimport React, { useMemo, type FC } from 'react';\nimport type { SelectButtonItem } from '../../types/selectButton';\nimport Button from '../button/Button';\nimport { StyledSelectButton } from './SelectButton.styles';\n\nexport type SelectButtonProps = {\n /**\n * The text that should be displayed inside the button.\n */\n buttonText: string;\n /**\n * Whether the button should be disabled.\n */\n isDisabled?: boolean;\n /**\n * A list of item that could be selected.\n */\n list: SelectButtonItem[];\n /**\n * Function to be executed after an item is selected.\n */\n onSelect?: (ids: number[]) => void;\n /**\n * If a string is given and `shouldAllowMultiSelect` is true, the dialog displays a checkbox to select all items at once.\n */\n selectAllText?: string;\n /**\n * The id of an item that should be preselected.\n */\n selectedItemIds?: number[];\n /**\n * Whether more than one item should be selectable.\n */\n shouldAllowMultiSelect?: boolean;\n /**\n * Whether the button text should be displayed also if items are selected.\n */\n shouldShowButtonTextWithSelection?: boolean;\n /**\n * Whether the search should be displayed inside the dialog.\n */\n shouldShowSearch?: boolean;\n /**\n * The title of the dialog.\n */\n title?: string;\n};\n\nconst SelectButton: FC<SelectButtonProps> = ({\n buttonText,\n isDisabled,\n list,\n onSelect,\n selectedItemIds,\n shouldAllowMultiSelect,\n shouldShowButtonTextWithSelection,\n shouldShowSearch,\n selectAllText,\n title,\n}) => {\n const itemList = useMemo(() => {\n const items: DialogSelectListItemType[] = [];\n\n list.forEach(({ text, id }) => {\n const isSelected = selectedItemIds ? selectedItemIds.includes(id) : false;\n\n items.push({\n name: text,\n id,\n isSelected,\n });\n });\n\n return items;\n }, [list, selectedItemIds]);\n\n const internalButtonText = useMemo(() => {\n if (shouldShowButtonTextWithSelection || !selectedItemIds || selectedItemIds.length === 0) {\n return buttonText;\n }\n\n let addedCount = 0;\n let newText = '';\n\n const additionalCount = selectedItemIds.length -
|
|
1
|
+
{"version":3,"file":"SelectButton.js","names":["createDialog","DialogType","React","useMemo","Button","StyledSelectButton","SelectButton","_ref","buttonText","isDisabled","list","onSelect","selectedItemIds","shouldAllowMultiSelect","shouldShowButtonTextWithSelection","maxDisplayedItems","additionalText","shouldShowSearch","selectAllText","title","itemList","items","forEach","_ref2","text","id","isSelected","includes","push","name","internalButtonText","length","addedCount","newText","additionalCount","_ref3","replace","String","handleClick","undefined","type","SELECT","multiselect","quickfind","selectAllCheckbox","open","then","result","buttonType","map","Number","createElement","onClick","isSecondary","shouldShowTextAsRobotoMedium","displayName"],"sources":["../../../../src/components/select-button/SelectButton.tsx"],"sourcesContent":["import { createDialog, DialogType, type DialogSelectListItemType } from 'chayns-api';\nimport React, { useMemo, type FC } from 'react';\nimport type { SelectButtonItem } from '../../types/selectButton';\nimport Button from '../button/Button';\nimport { StyledSelectButton } from './SelectButton.styles';\n\nexport type SelectButtonProps = {\n /**\n * Text used when there are more selected items than maxDisplayedItems. '##count##' will be displayed with the additional count.\n */\n additionalText?: string;\n /**\n * The text that should be displayed inside the button.\n */\n buttonText: string;\n /**\n * Whether the button should be disabled.\n */\n isDisabled?: boolean;\n /**\n * A list of item that could be selected.\n */\n list: SelectButtonItem[];\n /**\n * The maximum number of items displayed in the button text.\n */\n maxDisplayedItems?: number;\n /**\n * Function to be executed after an item is selected.\n */\n onSelect?: (ids: number[]) => void;\n /**\n * If a string is given and `shouldAllowMultiSelect` is true, the dialog displays a checkbox to select all items at once.\n */\n selectAllText?: string;\n /**\n * The id of an item that should be preselected.\n */\n selectedItemIds?: number[];\n /**\n * Whether more than one item should be selectable.\n */\n shouldAllowMultiSelect?: boolean;\n /**\n * Whether the button text should be displayed also if items are selected.\n */\n shouldShowButtonTextWithSelection?: boolean;\n /**\n * Whether the search should be displayed inside the dialog.\n */\n shouldShowSearch?: boolean;\n /**\n * The title of the dialog.\n */\n title?: string;\n};\n\nconst SelectButton: FC<SelectButtonProps> = ({\n buttonText,\n isDisabled,\n list,\n onSelect,\n selectedItemIds,\n shouldAllowMultiSelect,\n shouldShowButtonTextWithSelection,\n maxDisplayedItems = 3,\n additionalText = ', ##count## weitere',\n shouldShowSearch,\n selectAllText,\n title,\n}) => {\n const itemList = useMemo(() => {\n const items: DialogSelectListItemType[] = [];\n\n list.forEach(({ text, id }) => {\n const isSelected = selectedItemIds ? selectedItemIds.includes(id) : false;\n\n items.push({\n name: text,\n id,\n isSelected,\n });\n });\n\n return items;\n }, [list, selectedItemIds]);\n\n const internalButtonText = useMemo(() => {\n if (shouldShowButtonTextWithSelection || !selectedItemIds || selectedItemIds.length === 0) {\n return buttonText;\n }\n\n let addedCount = 0;\n let newText = '';\n\n const additionalCount = selectedItemIds.length - maxDisplayedItems;\n\n list.forEach(({ text, id }) => {\n if (addedCount < maxDisplayedItems && selectedItemIds?.includes(id)) {\n addedCount++;\n newText += newText.length === 0 ? `${text}` : `, ${text}`;\n }\n });\n\n if (additionalCount >= 1) {\n newText += additionalText.replace('##count##', String(additionalCount));\n }\n\n return newText;\n }, [\n additionalText,\n buttonText,\n list,\n maxDisplayedItems,\n selectedItemIds,\n shouldShowButtonTextWithSelection,\n ]);\n\n const handleClick = () => {\n void createDialog({\n text: title ? `[h1]${title}[/h1]` : undefined,\n type: DialogType.SELECT,\n list: itemList,\n multiselect: shouldAllowMultiSelect,\n quickfind: shouldShowSearch,\n selectAllCheckbox: selectAllText,\n })\n .open()\n .then((result) => {\n // Ignore because there is no type\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n if (result && result.buttonType === 1 && typeof onSelect === 'function') {\n // Ignore because there is no type\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n onSelect((result.result as string[]).map(Number));\n }\n });\n };\n\n return (\n <StyledSelectButton>\n <Button\n onClick={handleClick}\n isDisabled={isDisabled}\n isSecondary\n shouldShowTextAsRobotoMedium={false}\n >\n {internalButtonText}\n </Button>\n </StyledSelectButton>\n );\n};\n\nSelectButton.displayName = 'SelectButton';\n\nexport default SelectButton;\n"],"mappings":"AAAA,SAASA,YAAY,EAAEC,UAAU,QAAuC,YAAY;AACpF,OAAOC,KAAK,IAAIC,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AAW;IACXC,4BAA4B,EAAE;EAAM,GAEnCxB,kBACG,CACQ,CAAC;AAE7B,CAAC;AAEDxB,YAAY,CAACiD,WAAW,GAAG,cAAc;AAEzC,eAAejD,YAAY","ignoreList":[]}
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { type FC } from 'react';
|
|
2
2
|
import type { SelectButtonItem } from '../../types/selectButton';
|
|
3
3
|
export type SelectButtonProps = {
|
|
4
|
+
/**
|
|
5
|
+
* Text used when there are more selected items than maxDisplayedItems. '##count##' will be displayed with the additional count.
|
|
6
|
+
*/
|
|
7
|
+
additionalText?: string;
|
|
4
8
|
/**
|
|
5
9
|
* The text that should be displayed inside the button.
|
|
6
10
|
*/
|
|
@@ -13,6 +17,10 @@ export type SelectButtonProps = {
|
|
|
13
17
|
* A list of item that could be selected.
|
|
14
18
|
*/
|
|
15
19
|
list: SelectButtonItem[];
|
|
20
|
+
/**
|
|
21
|
+
* The maximum number of items displayed in the button text.
|
|
22
|
+
*/
|
|
23
|
+
maxDisplayedItems?: number;
|
|
16
24
|
/**
|
|
17
25
|
* Function to be executed after an item is selected.
|
|
18
26
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chayns-components/core",
|
|
3
|
-
"version": "5.0.0-beta.
|
|
3
|
+
"version": "5.0.0-beta.895",
|
|
4
4
|
"description": "A set of beautiful React components for developing your own applications with chayns.",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"browserslist": [
|
|
@@ -87,5 +87,5 @@
|
|
|
87
87
|
"publishConfig": {
|
|
88
88
|
"access": "public"
|
|
89
89
|
},
|
|
90
|
-
"gitHead": "
|
|
90
|
+
"gitHead": "37ef0444d17868ba15c3d7b6ae497468c2db1918"
|
|
91
91
|
}
|