@webiny/admin-ui 0.0.0-unstable.e53eceafb5 → 0.0.0-unstable.eb196ccd2f

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.
Files changed (73) hide show
  1. package/Alert/Alert.d.ts +1 -1
  2. package/Button/IconButton.d.ts +1 -1
  3. package/Card/components/CardRoot.d.ts +3 -3
  4. package/Command/Command.d.ts +5 -5
  5. package/Dialog/components/DialogContent.d.ts +1 -1
  6. package/Dialog/components/DialogFooter.d.ts +1 -1
  7. package/Dialog/components/DialogTitle.d.ts +1 -1
  8. package/Grid/Grid.d.ts +4 -4
  9. package/Heading/Heading.d.ts +1 -1
  10. package/Link/Link.d.ts +1 -1
  11. package/RadioGroup/primitives/RadioGroupPrimitive.js +1 -1
  12. package/RadioGroup/primitives/RadioGroupPrimitive.js.map +1 -1
  13. package/Separator/Separator.d.ts +2 -2
  14. package/Skeleton/Skeleton.d.ts +1 -1
  15. package/Slider/primitives/components/SliderTooltip.d.ts +1 -1
  16. package/Tag/Tag.d.ts +1 -1
  17. package/Tags/Tags.d.ts +24 -0
  18. package/Tags/Tags.js +59 -0
  19. package/Tags/Tags.js.map +1 -0
  20. package/Tags/Tags.stories.d.ts +13 -0
  21. package/Tags/Tags.stories.js +92 -0
  22. package/Tags/Tags.stories.js.map +1 -0
  23. package/Tags/domain/TagItem.d.ts +18 -0
  24. package/Tags/domain/TagItem.js +26 -0
  25. package/Tags/domain/TagItem.js.map +1 -0
  26. package/Tags/domain/TagItemDto.d.ts +5 -0
  27. package/Tags/domain/TagItemDto.js +3 -0
  28. package/Tags/domain/TagItemDto.js.map +1 -0
  29. package/Tags/domain/TagItemFormatted.d.ts +5 -0
  30. package/Tags/domain/TagItemFormatted.js +3 -0
  31. package/Tags/domain/TagItemFormatted.js.map +1 -0
  32. package/Tags/domain/TagItemMapper.d.ts +5 -0
  33. package/Tags/domain/TagItemMapper.js +11 -0
  34. package/Tags/domain/TagItemMapper.js.map +1 -0
  35. package/Tags/domain/index.d.ts +4 -0
  36. package/Tags/domain/index.js +6 -0
  37. package/Tags/domain/index.js.map +1 -0
  38. package/Tags/index.d.ts +1 -0
  39. package/Tags/index.js +3 -0
  40. package/Tags/index.js.map +1 -0
  41. package/Tags/primitives/TagsPrimitive.d.ts +81 -0
  42. package/Tags/primitives/TagsPrimitive.js +54 -0
  43. package/Tags/primitives/TagsPrimitive.js.map +1 -0
  44. package/Tags/primitives/TagsPrimitive.stories.d.ts +26 -0
  45. package/Tags/primitives/TagsPrimitive.stories.js +185 -0
  46. package/Tags/primitives/TagsPrimitive.stories.js.map +1 -0
  47. package/Tags/primitives/index.d.ts +1 -0
  48. package/Tags/primitives/index.js +3 -0
  49. package/Tags/primitives/index.js.map +1 -0
  50. package/Tags/primitives/presenters/TagsInputPresenter.d.ts +22 -0
  51. package/Tags/primitives/presenters/TagsInputPresenter.js +22 -0
  52. package/Tags/primitives/presenters/TagsInputPresenter.js.map +1 -0
  53. package/Tags/primitives/presenters/TagsPresenter.d.ts +42 -0
  54. package/Tags/primitives/presenters/TagsPresenter.js +68 -0
  55. package/Tags/primitives/presenters/TagsPresenter.js.map +1 -0
  56. package/Tags/primitives/presenters/TagsPresenter.test.d.ts +1 -0
  57. package/Tags/primitives/presenters/TagsPresenter.test.js +220 -0
  58. package/Tags/primitives/presenters/TagsPresenter.test.js.map +1 -0
  59. package/Tags/primitives/presenters/TagsValuesPresenter.d.ts +28 -0
  60. package/Tags/primitives/presenters/TagsValuesPresenter.js +41 -0
  61. package/Tags/primitives/presenters/TagsValuesPresenter.js.map +1 -0
  62. package/Tags/primitives/presenters/index.d.ts +3 -0
  63. package/Tags/primitives/presenters/index.js +5 -0
  64. package/Tags/primitives/presenters/index.js.map +1 -0
  65. package/Tags/primitives/useTags.d.ts +15 -0
  66. package/Tags/primitives/useTags.js +36 -0
  67. package/Tags/primitives/useTags.js.map +1 -0
  68. package/Textarea/Textarea.d.ts +1 -1
  69. package/Textarea/Textarea.js.map +1 -1
  70. package/index.d.ts +1 -0
  71. package/index.js +1 -0
  72. package/index.js.map +1 -1
  73. package/package.json +9 -8
@@ -0,0 +1,81 @@
1
+ import React from "react";
2
+ import { type InputPrimitiveProps } from "../../Input";
3
+ import type { Icon } from "../../Icon";
4
+ interface TagsPrimitiveProps extends Omit<React.InputHTMLAttributes<HTMLInputElement>, "size" | "onChange"> {
5
+ /**
6
+ * Indicates if the field is disabled.
7
+ */
8
+ disabled?: boolean;
9
+ /**
10
+ * Reference to the input element.
11
+ */
12
+ inputRef?: React.Ref<HTMLInputElement>;
13
+ /**
14
+ * Indicates if the input field is invalid.
15
+ */
16
+ invalid?: boolean;
17
+ /**
18
+ * Callback triggered when a tag is added or removed.
19
+ */
20
+ onChange?: (values: string[]) => void;
21
+ /**
22
+ * Callback triggered when the input value changes.
23
+ */
24
+ onValueInput?: (value: string) => void;
25
+ /**
26
+ * Callback triggered when the value is added to the list.
27
+ */
28
+ onValueAdd?: (value: string) => void;
29
+ /**
30
+ * Callback triggered when a tag is removed.
31
+ */
32
+ onValueRemove?: (value: string) => void;
33
+ /**
34
+ * Placeholder text for the input field.
35
+ */
36
+ placeholder?: string;
37
+ /**
38
+ * Size of the input field.
39
+ * Refer to `InputPrimitiveProps["size"]` for possible values.
40
+ */
41
+ size?: InputPrimitiveProps["size"];
42
+ /**
43
+ * Icon to be displayed at the start of the input field.
44
+ */
45
+ startIcon?: React.ReactElement<typeof Icon> | React.ReactElement;
46
+ /**
47
+ * Variant of the input field.
48
+ * Refer to `InputPrimitiveProps["variant"]` for possible values.
49
+ */
50
+ variant?: InputPrimitiveProps["variant"];
51
+ /**
52
+ * Optional selected item.
53
+ */
54
+ value?: string[];
55
+ /**
56
+ * Protected values cannot be removed by the user, these can be simple strings or regex patterns.
57
+ */
58
+ protectedValues?: string[];
59
+ }
60
+ declare const TagsPrimitive: ((props: TagsPrimitiveProps) => React.JSX.Element) & {
61
+ original: (props: TagsPrimitiveProps) => React.JSX.Element;
62
+ originalName: string;
63
+ displayName: string;
64
+ } & {
65
+ original: ((props: TagsPrimitiveProps) => React.JSX.Element) & {
66
+ original: (props: TagsPrimitiveProps) => React.JSX.Element;
67
+ originalName: string;
68
+ displayName: string;
69
+ };
70
+ originalName: string;
71
+ displayName: string;
72
+ } & {
73
+ createDecorator: (decorator: import("@webiny/react-composition").ComponentDecorator<((props: TagsPrimitiveProps) => React.JSX.Element) & {
74
+ original: (props: TagsPrimitiveProps) => React.JSX.Element;
75
+ originalName: string; /**
76
+ * Indicates if the input field is invalid.
77
+ */
78
+ displayName: string;
79
+ }>) => (props: unknown) => React.JSX.Element;
80
+ };
81
+ export { TagsPrimitive, type TagsPrimitiveProps };
@@ -0,0 +1,54 @@
1
+ import React, { useMemo } from "react";
2
+ import { ReactComponent as AddIcon } from "@webiny/icons/add.svg";
3
+ import { makeDecoratable } from "../../utils";
4
+ import { useTags } from "./useTags";
5
+ import { InputPrimitive } from "../../Input";
6
+ import { Tag } from "../../Tag";
7
+ import { IconButton } from "../../Button";
8
+ const DecoratableTagsPrimitive = props => {
9
+ const {
10
+ vm,
11
+ inputValue,
12
+ addValue,
13
+ removeValue
14
+ } = useTags(props);
15
+ const inputProps = useMemo(() => ({
16
+ disabled: props.disabled,
17
+ inputRef: props.inputRef,
18
+ invalid: props.invalid,
19
+ onChange: inputValue,
20
+ placeholder: props.placeholder,
21
+ size: props.size,
22
+ variant: props.variant
23
+ }), [props]);
24
+
25
+ // When user press Enter, add the current input value as a tag
26
+ const handleKeyDown = event => {
27
+ if (event.key === "Enter" && event.target) {
28
+ event.preventDefault();
29
+ addValue();
30
+ }
31
+ };
32
+ return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(InputPrimitive, Object.assign({}, inputProps, vm.inputVm, {
33
+ onChange: inputValue,
34
+ onKeyDown: handleKeyDown,
35
+ startIcon: props.startIcon,
36
+ endIcon: /*#__PURE__*/React.createElement(IconButton, {
37
+ onClick: addValue,
38
+ icon: /*#__PURE__*/React.createElement(AddIcon, null),
39
+ variant: "ghost",
40
+ disabled: inputProps.disabled
41
+ })
42
+ })), vm.valuesVm.values.length > 0 && /*#__PURE__*/React.createElement("div", {
43
+ className: "wby-mt-sm wby-flex wby-flex-wrap wby-gap-xs"
44
+ }, vm.valuesVm.values.map(tag => /*#__PURE__*/React.createElement(Tag, {
45
+ key: tag.id,
46
+ content: tag.label,
47
+ onDismiss: !tag.protected ? () => removeValue(tag.label) : undefined,
48
+ variant: "neutral-muted"
49
+ }))));
50
+ };
51
+ const TagsPrimitive = makeDecoratable("TagsPrimitive", DecoratableTagsPrimitive);
52
+ export { TagsPrimitive };
53
+
54
+ //# sourceMappingURL=TagsPrimitive.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["React","useMemo","ReactComponent","AddIcon","makeDecoratable","useTags","InputPrimitive","Tag","IconButton","DecoratableTagsPrimitive","props","vm","inputValue","addValue","removeValue","inputProps","disabled","inputRef","invalid","onChange","placeholder","size","variant","handleKeyDown","event","key","target","preventDefault","createElement","Object","assign","inputVm","onKeyDown","startIcon","endIcon","onClick","icon","valuesVm","values","length","className","map","tag","id","content","label","onDismiss","protected","undefined","TagsPrimitive"],"sources":["TagsPrimitive.tsx"],"sourcesContent":["import React, { useMemo } from \"react\";\nimport { ReactComponent as AddIcon } from \"@webiny/icons/add.svg\";\nimport { makeDecoratable } from \"~/utils\";\nimport { useTags } from \"./useTags\";\nimport { InputPrimitive, type InputPrimitiveProps } from \"~/Input\";\nimport { Tag } from \"~/Tag\";\nimport { IconButton } from \"~/Button\";\nimport type { Icon } from \"~/Icon\";\n\ninterface TagsPrimitiveProps\n extends Omit<React.InputHTMLAttributes<HTMLInputElement>, \"size\" | \"onChange\"> {\n /**\n * Indicates if the field is disabled.\n */\n disabled?: boolean;\n /**\n * Reference to the input element.\n */\n inputRef?: React.Ref<HTMLInputElement>;\n /**\n * Indicates if the input field is invalid.\n */\n invalid?: boolean;\n /**\n * Callback triggered when a tag is added or removed.\n */\n onChange?: (values: string[]) => void;\n /**\n * Callback triggered when the input value changes.\n */\n onValueInput?: (value: string) => void;\n /**\n * Callback triggered when the value is added to the list.\n */\n onValueAdd?: (value: string) => void;\n /**\n * Callback triggered when a tag is removed.\n */\n onValueRemove?: (value: string) => void;\n /**\n * Placeholder text for the input field.\n */\n placeholder?: string;\n /**\n * Size of the input field.\n * Refer to `InputPrimitiveProps[\"size\"]` for possible values.\n */\n size?: InputPrimitiveProps[\"size\"];\n /**\n * Icon to be displayed at the start of the input field.\n */\n startIcon?: React.ReactElement<typeof Icon> | React.ReactElement;\n /**\n * Variant of the input field.\n * Refer to `InputPrimitiveProps[\"variant\"]` for possible values.\n */\n variant?: InputPrimitiveProps[\"variant\"];\n /**\n * Optional selected item.\n */\n value?: string[];\n /**\n * Protected values cannot be removed by the user, these can be simple strings or regex patterns.\n */\n protectedValues?: string[];\n}\n\nconst DecoratableTagsPrimitive = (props: TagsPrimitiveProps) => {\n const { vm, inputValue, addValue, removeValue } = useTags(props);\n\n const inputProps: InputPrimitiveProps = useMemo(\n () => ({\n disabled: props.disabled,\n inputRef: props.inputRef,\n invalid: props.invalid,\n onChange: inputValue,\n placeholder: props.placeholder,\n size: props.size,\n variant: props.variant\n }),\n [props]\n );\n\n // When user press Enter, add the current input value as a tag\n const handleKeyDown = (event: React.KeyboardEvent<HTMLInputElement>) => {\n if (event.key === \"Enter\" && event.target) {\n event.preventDefault();\n addValue();\n }\n };\n\n return (\n <div>\n <InputPrimitive\n {...inputProps}\n {...vm.inputVm}\n onChange={inputValue}\n onKeyDown={handleKeyDown}\n startIcon={props.startIcon}\n endIcon={\n <IconButton\n onClick={addValue}\n icon={<AddIcon />}\n variant={\"ghost\"}\n disabled={inputProps.disabled}\n />\n }\n />\n\n {vm.valuesVm.values.length > 0 && (\n <div className={\"wby-mt-sm wby-flex wby-flex-wrap wby-gap-xs\"}>\n {vm.valuesVm.values.map(tag => (\n <Tag\n key={tag.id}\n content={tag.label}\n onDismiss={!tag.protected ? () => removeValue(tag.label) : undefined}\n variant={\"neutral-muted\"}\n />\n ))}\n </div>\n )}\n </div>\n );\n};\n\nconst TagsPrimitive = makeDecoratable(\"TagsPrimitive\", DecoratableTagsPrimitive);\n\nexport { TagsPrimitive, type TagsPrimitiveProps };\n"],"mappings":"AAAA,OAAOA,KAAK,IAAIC,OAAO,QAAQ,OAAO;AACtC,SAASC,cAAc,IAAIC,OAAO,QAAQ,uBAAuB;AACjE,SAASC,eAAe;AACxB,SAASC,OAAO;AAChB,SAASC,cAAc;AACvB,SAASC,GAAG;AACZ,SAASC,UAAU;AA6DnB,MAAMC,wBAAwB,GAAIC,KAAyB,IAAK;EAC5D,MAAM;IAAEC,EAAE;IAAEC,UAAU;IAAEC,QAAQ;IAAEC;EAAY,CAAC,GAAGT,OAAO,CAACK,KAAK,CAAC;EAEhE,MAAMK,UAA+B,GAAGd,OAAO,CAC3C,OAAO;IACHe,QAAQ,EAAEN,KAAK,CAACM,QAAQ;IACxBC,QAAQ,EAAEP,KAAK,CAACO,QAAQ;IACxBC,OAAO,EAAER,KAAK,CAACQ,OAAO;IACtBC,QAAQ,EAAEP,UAAU;IACpBQ,WAAW,EAAEV,KAAK,CAACU,WAAW;IAC9BC,IAAI,EAAEX,KAAK,CAACW,IAAI;IAChBC,OAAO,EAAEZ,KAAK,CAACY;EACnB,CAAC,CAAC,EACF,CAACZ,KAAK,CACV,CAAC;;EAED;EACA,MAAMa,aAAa,GAAIC,KAA4C,IAAK;IACpE,IAAIA,KAAK,CAACC,GAAG,KAAK,OAAO,IAAID,KAAK,CAACE,MAAM,EAAE;MACvCF,KAAK,CAACG,cAAc,CAAC,CAAC;MACtBd,QAAQ,CAAC,CAAC;IACd;EACJ,CAAC;EAED,oBACIb,KAAA,CAAA4B,aAAA,2BACI5B,KAAA,CAAA4B,aAAA,CAACtB,cAAc,EAAAuB,MAAA,CAAAC,MAAA,KACPf,UAAU,EACVJ,EAAE,CAACoB,OAAO;IACdZ,QAAQ,EAAEP,UAAW;IACrBoB,SAAS,EAAET,aAAc;IACzBU,SAAS,EAAEvB,KAAK,CAACuB,SAAU;IAC3BC,OAAO,eACHlC,KAAA,CAAA4B,aAAA,CAACpB,UAAU;MACP2B,OAAO,EAAEtB,QAAS;MAClBuB,IAAI,eAAEpC,KAAA,CAAA4B,aAAA,CAACzB,OAAO,MAAE,CAAE;MAClBmB,OAAO,EAAE,OAAQ;MACjBN,QAAQ,EAAED,UAAU,CAACC;IAAS,CACjC;EACJ,EACJ,CAAC,EAEDL,EAAE,CAAC0B,QAAQ,CAACC,MAAM,CAACC,MAAM,GAAG,CAAC,iBAC1BvC,KAAA,CAAA4B,aAAA;IAAKY,SAAS,EAAE;EAA8C,GACzD7B,EAAE,CAAC0B,QAAQ,CAACC,MAAM,CAACG,GAAG,CAACC,GAAG,iBACvB1C,KAAA,CAAA4B,aAAA,CAACrB,GAAG;IACAkB,GAAG,EAAEiB,GAAG,CAACC,EAAG;IACZC,OAAO,EAAEF,GAAG,CAACG,KAAM;IACnBC,SAAS,EAAE,CAACJ,GAAG,CAACK,SAAS,GAAG,MAAMjC,WAAW,CAAC4B,GAAG,CAACG,KAAK,CAAC,GAAGG,SAAU;IACrE1B,OAAO,EAAE;EAAgB,CAC5B,CACJ,CACA,CAER,CAAC;AAEd,CAAC;AAED,MAAM2B,aAAa,GAAG7C,eAAe,CAAC,eAAe,EAAEK,wBAAwB,CAAC;AAEhF,SAASwC,aAAa","ignoreList":[]}
@@ -0,0 +1,26 @@
1
+ import type { Meta, StoryObj } from "@storybook/react";
2
+ import { TagsPrimitive } from "./TagsPrimitive";
3
+ declare const meta: Meta<typeof TagsPrimitive>;
4
+ export default meta;
5
+ type Story = StoryObj<typeof TagsPrimitive>;
6
+ export declare const Default: Story;
7
+ export declare const MediumSize: Story;
8
+ export declare const LargeSize: Story;
9
+ export declare const ExtraLargeSize: Story;
10
+ export declare const PrimaryVariant: Story;
11
+ export declare const PrimaryVariantDisabled: Story;
12
+ export declare const PrimaryVariantInvalid: Story;
13
+ export declare const SecondaryVariant: Story;
14
+ export declare const SecondaryVariantDisabled: Story;
15
+ export declare const SecondaryVariantInvalid: Story;
16
+ export declare const GhostVariant: Story;
17
+ export declare const GhostVariantDisabled: Story;
18
+ export declare const GhostVariantInvalid: Story;
19
+ export declare const GhostNegativeVariant: Story;
20
+ export declare const GhostNegativeVariantDisabled: Story;
21
+ export declare const GhostNegativeVariantInvalid: Story;
22
+ export declare const WithCustomPlaceholder: Story;
23
+ export declare const WithStartIcon: Story;
24
+ export declare const WithInitialValues: Story;
25
+ export declare const WithProtectedValues: Story;
26
+ export declare const WithExternalValueControl: Story;
@@ -0,0 +1,185 @@
1
+ import React from "react";
2
+ import { ReactComponent as TagIcon } from "@webiny/icons/tag.svg";
3
+ import { TagsPrimitive } from "./TagsPrimitive";
4
+ import { Button } from "../../Button";
5
+ import { Icon } from "../../Icon";
6
+ const meta = {
7
+ title: "Components/Form Primitives/Tags",
8
+ component: TagsPrimitive,
9
+ argTypes: {
10
+ onChange: {
11
+ action: "onChange"
12
+ },
13
+ onValueInput: {
14
+ action: "onValueInput"
15
+ },
16
+ onValueAdd: {
17
+ action: "onValueAdd"
18
+ },
19
+ onValueRemove: {
20
+ action: "onValueRemove"
21
+ },
22
+ disabled: {
23
+ control: "boolean",
24
+ defaultValue: false
25
+ }
26
+ },
27
+ parameters: {
28
+ layout: "padded"
29
+ },
30
+ render: args => /*#__PURE__*/React.createElement(TagsPrimitive, args)
31
+ };
32
+ export default meta;
33
+ export const Default = {};
34
+ export const MediumSize = {
35
+ args: {
36
+ ...Default.args,
37
+ size: "md"
38
+ }
39
+ };
40
+ export const LargeSize = {
41
+ args: {
42
+ ...Default.args,
43
+ size: "lg"
44
+ }
45
+ };
46
+ export const ExtraLargeSize = {
47
+ args: {
48
+ ...Default.args,
49
+ size: "xl"
50
+ }
51
+ };
52
+ export const PrimaryVariant = {
53
+ args: {
54
+ ...Default.args,
55
+ variant: "primary"
56
+ }
57
+ };
58
+ export const PrimaryVariantDisabled = {
59
+ args: {
60
+ ...PrimaryVariant.args,
61
+ disabled: true
62
+ }
63
+ };
64
+ export const PrimaryVariantInvalid = {
65
+ args: {
66
+ ...PrimaryVariant.args,
67
+ invalid: true
68
+ }
69
+ };
70
+ export const SecondaryVariant = {
71
+ args: {
72
+ variant: "secondary",
73
+ placeholder: "Custom placeholder"
74
+ }
75
+ };
76
+ export const SecondaryVariantDisabled = {
77
+ args: {
78
+ ...SecondaryVariant.args,
79
+ disabled: true
80
+ }
81
+ };
82
+ export const SecondaryVariantInvalid = {
83
+ args: {
84
+ ...SecondaryVariant.args,
85
+ invalid: true
86
+ }
87
+ };
88
+ export const GhostVariant = {
89
+ args: {
90
+ variant: "ghost",
91
+ placeholder: "Custom placeholder"
92
+ }
93
+ };
94
+ export const GhostVariantDisabled = {
95
+ args: {
96
+ ...GhostVariant.args,
97
+ disabled: true
98
+ }
99
+ };
100
+ export const GhostVariantInvalid = {
101
+ args: {
102
+ ...GhostVariant.args,
103
+ invalid: true
104
+ }
105
+ };
106
+ export const GhostNegativeVariant = {
107
+ args: {
108
+ ...Default.args,
109
+ variant: "ghost-negative",
110
+ placeholder: "Custom placeholder"
111
+ },
112
+ decorators: [Story => /*#__PURE__*/React.createElement("div", {
113
+ className: "wby-bg-neutral-dark wby-text-neutral-light wby-p-xl"
114
+ }, /*#__PURE__*/React.createElement(Story, null))]
115
+ };
116
+ export const GhostNegativeVariantDisabled = {
117
+ args: {
118
+ ...GhostNegativeVariant.args,
119
+ disabled: true
120
+ },
121
+ decorators: [Story => /*#__PURE__*/React.createElement("div", {
122
+ className: "wby-bg-neutral-dark wby-text-neutral-light wby-p-xl"
123
+ }, /*#__PURE__*/React.createElement(Story, null))]
124
+ };
125
+ export const GhostNegativeVariantInvalid = {
126
+ args: {
127
+ ...GhostNegativeVariant.args,
128
+ invalid: true
129
+ },
130
+ decorators: [Story => /*#__PURE__*/React.createElement("div", {
131
+ className: "wby-bg-neutral-dark wby-text-neutral-light wby-p-xl"
132
+ }, /*#__PURE__*/React.createElement(Story, null))]
133
+ };
134
+ export const WithCustomPlaceholder = {
135
+ args: {
136
+ ...Default.args,
137
+ placeholder: "Custom placeholder"
138
+ }
139
+ };
140
+ export const WithStartIcon = {
141
+ args: {
142
+ ...Default.args,
143
+ startIcon: /*#__PURE__*/React.createElement(Icon, {
144
+ label: "Tag",
145
+ icon: /*#__PURE__*/React.createElement(TagIcon, null)
146
+ })
147
+ }
148
+ };
149
+ export const WithInitialValues = {
150
+ args: {
151
+ ...Default.args,
152
+ value: ["tag1", "tag2", "tag3"]
153
+ }
154
+ };
155
+ export const WithProtectedValues = {
156
+ args: {
157
+ ...Default.args,
158
+ value: ["tag1", "tag2", "tag3", "another-tag1", "another-tag2"],
159
+ protectedValues: ["tag1", "another-tag*"]
160
+ }
161
+ };
162
+ export const WithExternalValueControl = {
163
+ args: {
164
+ ...Default.args,
165
+ value: ["tag1", "tag2", "tag3"]
166
+ },
167
+ render: args => {
168
+ const [value, setValue] = React.useState(args.value || []);
169
+ return /*#__PURE__*/React.createElement("div", {
170
+ className: "wby-w-full"
171
+ }, /*#__PURE__*/React.createElement(TagsPrimitive, Object.assign({}, args, {
172
+ value: value,
173
+ onChange: setValue
174
+ })), /*#__PURE__*/React.createElement("div", {
175
+ className: "wby-mt-4 wby-text-center"
176
+ }, /*#__PURE__*/React.createElement(Button, {
177
+ text: "Reset",
178
+ onClick: () => setValue(args.value || [])
179
+ })), /*#__PURE__*/React.createElement("div", {
180
+ className: "wby-mt-4 wby-text-center"
181
+ }, "Current selected values: ", value?.join(",")));
182
+ }
183
+ };
184
+
185
+ //# sourceMappingURL=TagsPrimitive.stories.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["React","ReactComponent","TagIcon","TagsPrimitive","Button","Icon","meta","title","component","argTypes","onChange","action","onValueInput","onValueAdd","onValueRemove","disabled","control","defaultValue","parameters","layout","render","args","createElement","Default","MediumSize","size","LargeSize","ExtraLargeSize","PrimaryVariant","variant","PrimaryVariantDisabled","PrimaryVariantInvalid","invalid","SecondaryVariant","placeholder","SecondaryVariantDisabled","SecondaryVariantInvalid","GhostVariant","GhostVariantDisabled","GhostVariantInvalid","GhostNegativeVariant","decorators","Story","className","GhostNegativeVariantDisabled","GhostNegativeVariantInvalid","WithCustomPlaceholder","WithStartIcon","startIcon","label","icon","WithInitialValues","value","WithProtectedValues","protectedValues","WithExternalValueControl","setValue","useState","Object","assign","text","onClick","join"],"sources":["TagsPrimitive.stories.tsx"],"sourcesContent":["import React from \"react\";\nimport type { Meta, StoryObj } from \"@storybook/react\";\nimport { ReactComponent as TagIcon } from \"@webiny/icons/tag.svg\";\nimport { TagsPrimitive } from \"./TagsPrimitive\";\nimport { Button } from \"~/Button\";\nimport { Icon } from \"~/Icon\";\n\nconst meta: Meta<typeof TagsPrimitive> = {\n title: \"Components/Form Primitives/Tags\",\n component: TagsPrimitive,\n argTypes: {\n onChange: { action: \"onChange\" },\n onValueInput: { action: \"onValueInput\" },\n onValueAdd: { action: \"onValueAdd\" },\n onValueRemove: { action: \"onValueRemove\" },\n disabled: {\n control: \"boolean\",\n defaultValue: false\n }\n },\n parameters: {\n layout: \"padded\"\n },\n render: args => <TagsPrimitive {...args} />\n};\n\nexport default meta;\ntype Story = StoryObj<typeof TagsPrimitive>;\n\nexport const Default: Story = {};\n\nexport const MediumSize: Story = {\n args: {\n ...Default.args,\n size: \"md\"\n }\n};\n\nexport const LargeSize: Story = {\n args: {\n ...Default.args,\n size: \"lg\"\n }\n};\n\nexport const ExtraLargeSize: Story = {\n args: {\n ...Default.args,\n size: \"xl\"\n }\n};\n\nexport const PrimaryVariant: Story = {\n args: {\n ...Default.args,\n variant: \"primary\"\n }\n};\n\nexport const PrimaryVariantDisabled: Story = {\n args: {\n ...PrimaryVariant.args,\n disabled: true\n }\n};\n\nexport const PrimaryVariantInvalid: Story = {\n args: {\n ...PrimaryVariant.args,\n invalid: true\n }\n};\n\nexport const SecondaryVariant: Story = {\n args: {\n variant: \"secondary\",\n placeholder: \"Custom placeholder\"\n }\n};\n\nexport const SecondaryVariantDisabled: Story = {\n args: {\n ...SecondaryVariant.args,\n disabled: true\n }\n};\n\nexport const SecondaryVariantInvalid: Story = {\n args: {\n ...SecondaryVariant.args,\n invalid: true\n }\n};\n\nexport const GhostVariant: Story = {\n args: {\n variant: \"ghost\",\n placeholder: \"Custom placeholder\"\n }\n};\n\nexport const GhostVariantDisabled: Story = {\n args: {\n ...GhostVariant.args,\n disabled: true\n }\n};\n\nexport const GhostVariantInvalid: Story = {\n args: {\n ...GhostVariant.args,\n invalid: true\n }\n};\n\nexport const GhostNegativeVariant: Story = {\n args: {\n ...Default.args,\n variant: \"ghost-negative\",\n placeholder: \"Custom placeholder\"\n },\n decorators: [\n Story => (\n <div className=\"wby-bg-neutral-dark wby-text-neutral-light wby-p-xl\">\n <Story />\n </div>\n )\n ]\n};\n\nexport const GhostNegativeVariantDisabled: Story = {\n args: {\n ...GhostNegativeVariant.args,\n disabled: true\n },\n decorators: [\n Story => (\n <div className=\"wby-bg-neutral-dark wby-text-neutral-light wby-p-xl\">\n <Story />\n </div>\n )\n ]\n};\n\nexport const GhostNegativeVariantInvalid: Story = {\n args: {\n ...GhostNegativeVariant.args,\n invalid: true\n },\n decorators: [\n Story => (\n <div className=\"wby-bg-neutral-dark wby-text-neutral-light wby-p-xl\">\n <Story />\n </div>\n )\n ]\n};\n\nexport const WithCustomPlaceholder: Story = {\n args: {\n ...Default.args,\n placeholder: \"Custom placeholder\"\n }\n};\n\nexport const WithStartIcon: Story = {\n args: {\n ...Default.args,\n startIcon: <Icon label={\"Tag\"} icon={<TagIcon />} />\n }\n};\n\nexport const WithInitialValues: Story = {\n args: {\n ...Default.args,\n value: [\"tag1\", \"tag2\", \"tag3\"]\n }\n};\n\nexport const WithProtectedValues: Story = {\n args: {\n ...Default.args,\n value: [\"tag1\", \"tag2\", \"tag3\", \"another-tag1\", \"another-tag2\"],\n protectedValues: [\"tag1\", \"another-tag*\"]\n }\n};\n\nexport const WithExternalValueControl: Story = {\n args: {\n ...Default.args,\n value: [\"tag1\", \"tag2\", \"tag3\"]\n },\n render: args => {\n const [value, setValue] = React.useState<string[]>(args.value || []);\n\n return (\n <div className={\"wby-w-full\"}>\n <TagsPrimitive {...args} value={value} onChange={setValue} />\n <div className={\"wby-mt-4 wby-text-center\"}>\n <Button text={\"Reset\"} onClick={() => setValue(args.value || [])} />\n </div>\n <div className={\"wby-mt-4 wby-text-center\"}>\n Current selected values: {value?.join(\",\")}\n </div>\n </div>\n );\n }\n};\n"],"mappings":"AAAA,OAAOA,KAAK,MAAM,OAAO;AAEzB,SAASC,cAAc,IAAIC,OAAO,QAAQ,uBAAuB;AACjE,SAASC,aAAa;AACtB,SAASC,MAAM;AACf,SAASC,IAAI;AAEb,MAAMC,IAAgC,GAAG;EACrCC,KAAK,EAAE,iCAAiC;EACxCC,SAAS,EAAEL,aAAa;EACxBM,QAAQ,EAAE;IACNC,QAAQ,EAAE;MAAEC,MAAM,EAAE;IAAW,CAAC;IAChCC,YAAY,EAAE;MAAED,MAAM,EAAE;IAAe,CAAC;IACxCE,UAAU,EAAE;MAAEF,MAAM,EAAE;IAAa,CAAC;IACpCG,aAAa,EAAE;MAAEH,MAAM,EAAE;IAAgB,CAAC;IAC1CI,QAAQ,EAAE;MACNC,OAAO,EAAE,SAAS;MAClBC,YAAY,EAAE;IAClB;EACJ,CAAC;EACDC,UAAU,EAAE;IACRC,MAAM,EAAE;EACZ,CAAC;EACDC,MAAM,EAAEC,IAAI,iBAAIrB,KAAA,CAAAsB,aAAA,CAACnB,aAAa,EAAKkB,IAAO;AAC9C,CAAC;AAED,eAAef,IAAI;AAGnB,OAAO,MAAMiB,OAAc,GAAG,CAAC,CAAC;AAEhC,OAAO,MAAMC,UAAiB,GAAG;EAC7BH,IAAI,EAAE;IACF,GAAGE,OAAO,CAACF,IAAI;IACfI,IAAI,EAAE;EACV;AACJ,CAAC;AAED,OAAO,MAAMC,SAAgB,GAAG;EAC5BL,IAAI,EAAE;IACF,GAAGE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,EAAEU,IAAI,CAAC,GAAG,CACxC,CACJ,CAAC;EAEd;AACJ,CAAC","ignoreList":[]}
@@ -0,0 +1 @@
1
+ export * from "./TagsPrimitive";
@@ -0,0 +1,3 @@
1
+ export * from "./TagsPrimitive";
2
+
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"./TagsPrimitive\";\n"],"mappings":"AAAA","ignoreList":[]}
@@ -0,0 +1,22 @@
1
+ export interface TagsInputPresenterParams {
2
+ placeholder?: string;
3
+ }
4
+ export interface ITagsInputPresenter {
5
+ vm: {
6
+ placeholder: string;
7
+ value: string;
8
+ };
9
+ init: (params: TagsInputPresenterParams) => void;
10
+ setValue: (query: string) => void;
11
+ }
12
+ export declare class TagsInputPresenter implements ITagsInputPresenter {
13
+ private value?;
14
+ private placeholder?;
15
+ constructor();
16
+ init(params?: TagsInputPresenterParams): void;
17
+ get vm(): {
18
+ placeholder: string;
19
+ value: string;
20
+ };
21
+ setValue: (value: string) => void;
22
+ }
@@ -0,0 +1,22 @@
1
+ import { makeAutoObservable } from "mobx";
2
+ export class TagsInputPresenter {
3
+ value = undefined;
4
+ placeholder = undefined;
5
+ constructor() {
6
+ makeAutoObservable(this);
7
+ }
8
+ init(params) {
9
+ this.placeholder = params?.placeholder;
10
+ }
11
+ get vm() {
12
+ return {
13
+ placeholder: this.placeholder || "",
14
+ value: this.value || ""
15
+ };
16
+ }
17
+ setValue = value => {
18
+ this.value = value;
19
+ };
20
+ }
21
+
22
+ //# sourceMappingURL=TagsInputPresenter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["makeAutoObservable","TagsInputPresenter","value","undefined","placeholder","constructor","init","params","vm","setValue"],"sources":["TagsInputPresenter.ts"],"sourcesContent":["import { makeAutoObservable } from \"mobx\";\n\nexport interface TagsInputPresenterParams {\n placeholder?: string;\n}\n\nexport interface ITagsInputPresenter {\n vm: {\n placeholder: string;\n value: string;\n };\n init: (params: TagsInputPresenterParams) => void;\n setValue: (query: string) => void;\n}\n\nexport class TagsInputPresenter implements ITagsInputPresenter {\n private value?: string = undefined;\n private placeholder?: string = undefined;\n\n constructor() {\n makeAutoObservable(this);\n }\n\n init(params?: TagsInputPresenterParams) {\n this.placeholder = params?.placeholder;\n }\n\n get vm() {\n return {\n placeholder: this.placeholder || \"\",\n value: this.value || \"\"\n };\n }\n\n public setValue = (value: string) => {\n this.value = value;\n };\n}\n"],"mappings":"AAAA,SAASA,kBAAkB,QAAQ,MAAM;AAezC,OAAO,MAAMC,kBAAkB,CAAgC;EACnDC,KAAK,GAAYC,SAAS;EAC1BC,WAAW,GAAYD,SAAS;EAExCE,WAAWA,CAAA,EAAG;IACVL,kBAAkB,CAAC,IAAI,CAAC;EAC5B;EAEAM,IAAIA,CAACC,MAAiC,EAAE;IACpC,IAAI,CAACH,WAAW,GAAGG,MAAM,EAAEH,WAAW;EAC1C;EAEA,IAAII,EAAEA,CAAA,EAAG;IACL,OAAO;MACHJ,WAAW,EAAE,IAAI,CAACA,WAAW,IAAI,EAAE;MACnCF,KAAK,EAAE,IAAI,CAACA,KAAK,IAAI;IACzB,CAAC;EACL;EAEOO,QAAQ,GAAIP,KAAa,IAAK;IACjC,IAAI,CAACA,KAAK,GAAGA,KAAK;EACtB,CAAC;AACL","ignoreList":[]}
@@ -0,0 +1,42 @@
1
+ import { type ITagsInputPresenter } from "./TagsInputPresenter";
2
+ import { type ITagsValuesPresenter } from "./TagsValuesPresenter";
3
+ interface TagsPresenterParams {
4
+ values?: string[];
5
+ protectedValues?: string[];
6
+ onValueChange?: (values: string[]) => void;
7
+ onValueInput?: (value: string) => void;
8
+ onValueAdd?: (value: string) => void;
9
+ onValueRemove?: (value: string) => void;
10
+ placeholder?: string;
11
+ }
12
+ interface ITagsPresenter {
13
+ vm: {
14
+ inputVm: ITagsInputPresenter["vm"];
15
+ valuesVm: ITagsValuesPresenter["vm"];
16
+ };
17
+ init: (params: TagsPresenterParams) => void;
18
+ inputValue: (value: string) => void;
19
+ addValue: (value: string) => void;
20
+ removeValue: (value: string) => void;
21
+ }
22
+ declare class TagsPresenter implements ITagsPresenter {
23
+ private params?;
24
+ private inputPresenter;
25
+ private valuesPresenter;
26
+ constructor(inputPresenter: ITagsInputPresenter, valuesPresenter: ITagsValuesPresenter);
27
+ init(params: TagsPresenterParams): void;
28
+ get vm(): {
29
+ inputVm: {
30
+ placeholder: string;
31
+ value: string;
32
+ };
33
+ valuesVm: {
34
+ values: import("../../domain").TagItemFormatted[];
35
+ };
36
+ };
37
+ inputValue: (value: string) => void;
38
+ addValue: () => void;
39
+ removeValue: (value: string) => void;
40
+ private getValues;
41
+ }
42
+ export { TagsPresenter, type ITagsPresenter, type TagsPresenterParams };
@@ -0,0 +1,68 @@
1
+ import { makeAutoObservable } from "mobx";
2
+ class TagsPresenter {
3
+ params = undefined;
4
+ constructor(inputPresenter, valuesPresenter) {
5
+ this.inputPresenter = inputPresenter;
6
+ this.valuesPresenter = valuesPresenter;
7
+ makeAutoObservable(this);
8
+ }
9
+ init(params) {
10
+ this.params = params;
11
+ this.inputPresenter.init({
12
+ placeholder: params.placeholder
13
+ });
14
+ this.valuesPresenter.init({
15
+ values: params.values,
16
+ protectedValues: params.protectedValues
17
+ });
18
+ }
19
+ get vm() {
20
+ return {
21
+ inputVm: this.inputPresenter.vm,
22
+ valuesVm: this.valuesPresenter.vm
23
+ };
24
+ }
25
+ inputValue = value => {
26
+ this.inputPresenter.setValue(value);
27
+ if (this.params?.onValueInput) {
28
+ this.params.onValueInput(value);
29
+ }
30
+ };
31
+ addValue = () => {
32
+ const value = this.vm.inputVm.value.trim();
33
+ if (!value) {
34
+ return;
35
+ }
36
+ this.inputPresenter.setValue("");
37
+ if (this.valuesPresenter.hasValue(value)) {
38
+ // If the value already exists, do not add it again
39
+ return;
40
+ }
41
+ this.valuesPresenter.addValue(value);
42
+ if (this.params?.onValueAdd) {
43
+ this.params.onValueAdd(value);
44
+ }
45
+ if (this.params?.onValueChange) {
46
+ this.params.onValueChange(this.getValues());
47
+ }
48
+ };
49
+ removeValue = value => {
50
+ this.valuesPresenter.removeValue(value);
51
+ if (this.valuesPresenter.isValueProtected(value)) {
52
+ // If the value is protected, do not remove it
53
+ return;
54
+ }
55
+ if (this.params?.onValueRemove) {
56
+ this.params.onValueRemove(value);
57
+ }
58
+ if (this.params?.onValueChange) {
59
+ this.params.onValueChange(this.getValues());
60
+ }
61
+ };
62
+ getValues = () => {
63
+ return this.valuesPresenter.vm.values.map(tag => tag.label);
64
+ };
65
+ }
66
+ export { TagsPresenter };
67
+
68
+ //# sourceMappingURL=TagsPresenter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["makeAutoObservable","TagsPresenter","params","undefined","constructor","inputPresenter","valuesPresenter","init","placeholder","values","protectedValues","vm","inputVm","valuesVm","inputValue","value","setValue","onValueInput","addValue","trim","hasValue","onValueAdd","onValueChange","getValues","removeValue","isValueProtected","onValueRemove","map","tag","label"],"sources":["TagsPresenter.ts"],"sourcesContent":["import { makeAutoObservable } from \"mobx\";\nimport { type ITagsInputPresenter } from \"./TagsInputPresenter\";\nimport { type ITagsValuesPresenter } from \"./TagsValuesPresenter\";\n\ninterface TagsPresenterParams {\n values?: string[];\n protectedValues?: string[];\n onValueChange?: (values: string[]) => void;\n onValueInput?: (value: string) => void;\n onValueAdd?: (value: string) => void;\n onValueRemove?: (value: string) => void;\n placeholder?: string;\n}\n\ninterface ITagsPresenter {\n vm: {\n inputVm: ITagsInputPresenter[\"vm\"];\n valuesVm: ITagsValuesPresenter[\"vm\"];\n };\n init: (params: TagsPresenterParams) => void;\n inputValue: (value: string) => void;\n addValue: (value: string) => void;\n removeValue: (value: string) => void;\n}\n\nclass TagsPresenter implements ITagsPresenter {\n private params?: TagsPresenterParams = undefined;\n private inputPresenter: ITagsInputPresenter;\n private valuesPresenter: ITagsValuesPresenter;\n\n constructor(inputPresenter: ITagsInputPresenter, valuesPresenter: ITagsValuesPresenter) {\n this.inputPresenter = inputPresenter;\n this.valuesPresenter = valuesPresenter;\n makeAutoObservable(this);\n }\n\n init(params: TagsPresenterParams) {\n this.params = params;\n this.inputPresenter.init({ placeholder: params.placeholder });\n this.valuesPresenter.init({\n values: params.values,\n protectedValues: params.protectedValues\n });\n }\n\n get vm() {\n return {\n inputVm: this.inputPresenter.vm,\n valuesVm: this.valuesPresenter.vm\n };\n }\n\n public inputValue = (value: string) => {\n this.inputPresenter.setValue(value);\n if (this.params?.onValueInput) {\n this.params.onValueInput(value);\n }\n };\n\n public addValue = () => {\n const value = this.vm.inputVm.value.trim();\n\n if (!value) {\n return;\n }\n\n this.inputPresenter.setValue(\"\");\n\n if (this.valuesPresenter.hasValue(value)) {\n // If the value already exists, do not add it again\n return;\n }\n\n this.valuesPresenter.addValue(value);\n\n if (this.params?.onValueAdd) {\n this.params.onValueAdd(value);\n }\n\n if (this.params?.onValueChange) {\n this.params.onValueChange(this.getValues());\n }\n };\n\n public removeValue = (value: string) => {\n this.valuesPresenter.removeValue(value);\n\n if (this.valuesPresenter.isValueProtected(value)) {\n // If the value is protected, do not remove it\n return;\n }\n\n if (this.params?.onValueRemove) {\n this.params.onValueRemove(value);\n }\n\n if (this.params?.onValueChange) {\n this.params.onValueChange(this.getValues());\n }\n };\n\n private getValues = () => {\n return this.valuesPresenter.vm.values.map(tag => tag.label);\n };\n}\n\nexport { TagsPresenter, type ITagsPresenter, type TagsPresenterParams };\n"],"mappings":"AAAA,SAASA,kBAAkB,QAAQ,MAAM;AAyBzC,MAAMC,aAAa,CAA2B;EAClCC,MAAM,GAAyBC,SAAS;EAIhDC,WAAWA,CAACC,cAAmC,EAAEC,eAAqC,EAAE;IACpF,IAAI,CAACD,cAAc,GAAGA,cAAc;IACpC,IAAI,CAACC,eAAe,GAAGA,eAAe;IACtCN,kBAAkB,CAAC,IAAI,CAAC;EAC5B;EAEAO,IAAIA,CAACL,MAA2B,EAAE;IAC9B,IAAI,CAACA,MAAM,GAAGA,MAAM;IACpB,IAA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