draft-components 4.13.0 → 4.14.0
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/css/draft-components.css +162 -0
- package/dist/components/index.d.ts +1 -0
- package/dist/components/index.js +1 -0
- package/dist/components/index.js.map +1 -1
- package/dist/components/toaster/toaster.css +1 -0
- package/dist/components/token-input/index.d.ts +1 -0
- package/dist/components/token-input/index.js +2 -0
- package/dist/components/token-input/index.js.map +1 -0
- package/dist/components/token-input/token-input.css +160 -0
- package/dist/components/token-input/token-input.d.ts +24 -0
- package/dist/components/token-input/token-input.js +57 -0
- package/dist/components/token-input/token-input.js.map +1 -0
- package/package.json +1 -1
package/css/draft-components.css
CHANGED
|
@@ -2757,6 +2757,167 @@
|
|
|
2757
2757
|
color-scheme: dark;
|
|
2758
2758
|
}
|
|
2759
2759
|
|
|
2760
|
+
.dc-token-input {
|
|
2761
|
+
--color: var(--dc-neutral-900);
|
|
2762
|
+
--background: var(--dc-white);
|
|
2763
|
+
--border-color: var(--dc-neutral-300);
|
|
2764
|
+
--border-color-error: var(--dc-red-500);
|
|
2765
|
+
--focus-ring-color: var(--dc-focus-ring-color);
|
|
2766
|
+
--input-padding: 0 9px;
|
|
2767
|
+
--token-height: 28px;
|
|
2768
|
+
--token-padding: 0 0 0 8px;
|
|
2769
|
+
--token-color: var(--dc-neutral-950);
|
|
2770
|
+
--token-background: var(--dc-neutral-200);
|
|
2771
|
+
--token-background-hover: rgb(var(--dc-neutral-950-rgb) / 15%);
|
|
2772
|
+
--token-border-radius: 3px;
|
|
2773
|
+
|
|
2774
|
+
box-sizing: border-box;
|
|
2775
|
+
display: inline-flex;
|
|
2776
|
+
flex-wrap: wrap;
|
|
2777
|
+
gap: 3px;
|
|
2778
|
+
align-items: center;
|
|
2779
|
+
width: 100%;
|
|
2780
|
+
min-width: 0;
|
|
2781
|
+
min-height: 36px;
|
|
2782
|
+
padding: 3px;
|
|
2783
|
+
font: 400 14px/1 var(--dc-primary-font);
|
|
2784
|
+
color-scheme: light;
|
|
2785
|
+
background: var(--background);
|
|
2786
|
+
border: 1px solid var(--border-color);
|
|
2787
|
+
border-radius: 7px;
|
|
2788
|
+
}
|
|
2789
|
+
|
|
2790
|
+
.dc-token-input[data-disabled="true"] {
|
|
2791
|
+
opacity: var(--dc-disabled-state-opacity);
|
|
2792
|
+
}
|
|
2793
|
+
|
|
2794
|
+
.dc-token-input[data-invalid="true"] {
|
|
2795
|
+
border-color: var(--border-color-error);
|
|
2796
|
+
}
|
|
2797
|
+
|
|
2798
|
+
.dc-token-input:focus-within {
|
|
2799
|
+
border-color: var(--focus-ring-color);
|
|
2800
|
+
box-shadow: 0 0 0 1px var(--focus-ring-color);
|
|
2801
|
+
}
|
|
2802
|
+
|
|
2803
|
+
.dc-token-input_size_sm {
|
|
2804
|
+
--input-padding: 0 5px;
|
|
2805
|
+
--token-height: 24px;
|
|
2806
|
+
--token-padding: 0 0 0 8px;
|
|
2807
|
+
--token-border-radius: 2px;
|
|
2808
|
+
|
|
2809
|
+
gap: 3px;
|
|
2810
|
+
min-height: 32px;
|
|
2811
|
+
padding: 3px;
|
|
2812
|
+
font-size: 13px;
|
|
2813
|
+
border-radius: 6px;
|
|
2814
|
+
}
|
|
2815
|
+
|
|
2816
|
+
.dc-token-input_size_lg {
|
|
2817
|
+
--input-padding: 0 12px;
|
|
2818
|
+
--token-height: 30px;
|
|
2819
|
+
--token-padding: 0 0 0 12px;
|
|
2820
|
+
--token-border-radius: 3px;
|
|
2821
|
+
|
|
2822
|
+
gap: 4px;
|
|
2823
|
+
min-height: 40px;
|
|
2824
|
+
padding: 4px;
|
|
2825
|
+
font-size: 15px;
|
|
2826
|
+
border-radius: 8px;
|
|
2827
|
+
}
|
|
2828
|
+
|
|
2829
|
+
.dc-token-input > input {
|
|
2830
|
+
flex-grow: 1;
|
|
2831
|
+
width: auto;
|
|
2832
|
+
min-width: 10ch;
|
|
2833
|
+
padding: var(--input-padding);
|
|
2834
|
+
font: inherit;
|
|
2835
|
+
line-height: 1.5;
|
|
2836
|
+
background: none;
|
|
2837
|
+
border: none;
|
|
2838
|
+
}
|
|
2839
|
+
|
|
2840
|
+
.dc-token-input > input::-moz-placeholder {
|
|
2841
|
+
color: inherit;
|
|
2842
|
+
opacity: 0.4;
|
|
2843
|
+
}
|
|
2844
|
+
|
|
2845
|
+
.dc-token-input > input::placeholder {
|
|
2846
|
+
color: inherit;
|
|
2847
|
+
opacity: 0.4;
|
|
2848
|
+
}
|
|
2849
|
+
|
|
2850
|
+
.dc-token-input > input:not(:only-child) {
|
|
2851
|
+
padding-right: 0.25em;
|
|
2852
|
+
padding-left: 0.25em;
|
|
2853
|
+
}
|
|
2854
|
+
|
|
2855
|
+
.dc-token-input > input:focus {
|
|
2856
|
+
outline: none;
|
|
2857
|
+
}
|
|
2858
|
+
|
|
2859
|
+
.dc-token-input__token {
|
|
2860
|
+
display: inline-flex;
|
|
2861
|
+
gap: 2px;
|
|
2862
|
+
max-width: 100%;
|
|
2863
|
+
min-height: var(--token-height);
|
|
2864
|
+
padding: var(--token-padding);
|
|
2865
|
+
font: inherit;
|
|
2866
|
+
color: var(--token-color);
|
|
2867
|
+
cursor: default;
|
|
2868
|
+
background: var(--token-background);
|
|
2869
|
+
border-radius: var(--token-border-radius);
|
|
2870
|
+
}
|
|
2871
|
+
|
|
2872
|
+
.dc-token-input__token > span {
|
|
2873
|
+
padding: calc((var(--token-height) - 20px) / 2) 0;
|
|
2874
|
+
line-height: 20px;
|
|
2875
|
+
}
|
|
2876
|
+
|
|
2877
|
+
.dc-token-input__token > button {
|
|
2878
|
+
display: inline-flex;
|
|
2879
|
+
flex-shrink: 0;
|
|
2880
|
+
align-items: center;
|
|
2881
|
+
justify-content: center;
|
|
2882
|
+
width: var(--token-height);
|
|
2883
|
+
height: var(--token-height);
|
|
2884
|
+
padding: 0;
|
|
2885
|
+
font: inherit;
|
|
2886
|
+
line-height: 1;
|
|
2887
|
+
color: inherit;
|
|
2888
|
+
-webkit-appearance: none;
|
|
2889
|
+
-moz-appearance: none;
|
|
2890
|
+
appearance: none;
|
|
2891
|
+
cursor: default;
|
|
2892
|
+
background: none;
|
|
2893
|
+
border: none;
|
|
2894
|
+
border-radius: inherit;
|
|
2895
|
+
opacity: 0.5;
|
|
2896
|
+
}
|
|
2897
|
+
|
|
2898
|
+
.dc-token-input__token > button:focus {
|
|
2899
|
+
outline: none;
|
|
2900
|
+
}
|
|
2901
|
+
|
|
2902
|
+
.dc-token-input__token > button:not(:disabled):hover,
|
|
2903
|
+
.dc-token-input__token > button:not(:disabled):focus-visible {
|
|
2904
|
+
background: var(--token-background-hover);
|
|
2905
|
+
opacity: 1;
|
|
2906
|
+
}
|
|
2907
|
+
|
|
2908
|
+
.dark .dc-token-input,
|
|
2909
|
+
.dark.dc-token-input {
|
|
2910
|
+
--color: var(--dc-white);
|
|
2911
|
+
--background: var(--dc-neutral-800);
|
|
2912
|
+
--border-color: var(--dc-neutral-600);
|
|
2913
|
+
--border-color-error: var(--dc-red-400);
|
|
2914
|
+
--token-color: var(--dc-white);
|
|
2915
|
+
--token-background: var(--dc-neutral-600);
|
|
2916
|
+
--token-background-hover: rgb(var(--dc-neutral-50-rgb) / 15%);
|
|
2917
|
+
|
|
2918
|
+
color-scheme: dark;
|
|
2919
|
+
}
|
|
2920
|
+
|
|
2760
2921
|
.dc-password-input {
|
|
2761
2922
|
padding-right: 0;
|
|
2762
2923
|
color-scheme: light;
|
|
@@ -4949,6 +5110,7 @@
|
|
|
4949
5110
|
.dc-toasts-list {
|
|
4950
5111
|
--padding: 16px;
|
|
4951
5112
|
--animation: 200ms ease;
|
|
5113
|
+
--z-index: calc(infinity + 1);
|
|
4952
5114
|
|
|
4953
5115
|
position: fixed;
|
|
4954
5116
|
right: var(--padding);
|
|
@@ -36,5 +36,6 @@ export * from './tag/index.js';
|
|
|
36
36
|
export * from './text-input/index.js';
|
|
37
37
|
export * from './textarea/index.js';
|
|
38
38
|
export * from './toast/index.js';
|
|
39
|
+
export * from './token-input/index.js';
|
|
39
40
|
export * from './toaster/index.js';
|
|
40
41
|
export * from './tooltip/index.js';
|
package/dist/components/index.js
CHANGED
|
@@ -36,6 +36,7 @@ export * from './tag/index.js';
|
|
|
36
36
|
export * from './text-input/index.js';
|
|
37
37
|
export * from './textarea/index.js';
|
|
38
38
|
export * from './toast/index.js';
|
|
39
|
+
export * from './token-input/index.js';
|
|
39
40
|
export * from './toaster/index.js';
|
|
40
41
|
export * from './tooltip/index.js';
|
|
41
42
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/components/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,cAAc,wBAAwB,CAAC;AACvC,cAAc,yBAAyB,CAAC;AACxC,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,yBAAyB,CAAC;AACxC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,wBAAwB,CAAC;AACvC,cAAc,sCAAsC,CAAC;AACrD,cAAc,mBAAmB,CAAC;AAClC,cAAc,wBAAwB,CAAC;AACvC,cAAc,wBAAwB,CAAC;AACvC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,uBAAuB,CAAC;AACtC,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,qBAAqB,CAAC;AACpC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,oBAAoB,CAAC;AACnC,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,cAAc,0BAA0B,CAAC;AACzC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,mBAAmB,CAAC;AAClC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,mBAAmB,CAA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Ac,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,uBAAuB,CAAC;AACtC,cAAc,qBAAqB,CAAC;AACpC,cAAc,kBAAkB,CAAC;AACjC,cAAc,wBAAwB,CAAC;AACvC,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './token-input.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/token-input/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
.dc-token-input {
|
|
2
|
+
--color: var(--dc-neutral-900);
|
|
3
|
+
--background: var(--dc-white);
|
|
4
|
+
--border-color: var(--dc-neutral-300);
|
|
5
|
+
--border-color-error: var(--dc-red-500);
|
|
6
|
+
--focus-ring-color: var(--dc-focus-ring-color);
|
|
7
|
+
--input-padding: 0 9px;
|
|
8
|
+
--token-height: 28px;
|
|
9
|
+
--token-padding: 0 0 0 8px;
|
|
10
|
+
--token-color: var(--dc-neutral-950);
|
|
11
|
+
--token-background: var(--dc-neutral-200);
|
|
12
|
+
--token-background-hover: rgb(var(--dc-neutral-950-rgb) / 15%);
|
|
13
|
+
--token-border-radius: 3px;
|
|
14
|
+
|
|
15
|
+
box-sizing: border-box;
|
|
16
|
+
display: inline-flex;
|
|
17
|
+
flex-wrap: wrap;
|
|
18
|
+
gap: 3px;
|
|
19
|
+
align-items: center;
|
|
20
|
+
width: 100%;
|
|
21
|
+
min-width: 0;
|
|
22
|
+
min-height: 36px;
|
|
23
|
+
padding: 3px;
|
|
24
|
+
font: 400 14px/1 var(--dc-primary-font);
|
|
25
|
+
color-scheme: light;
|
|
26
|
+
background: var(--background);
|
|
27
|
+
border: 1px solid var(--border-color);
|
|
28
|
+
border-radius: 7px;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
.dc-token-input[data-disabled="true"] {
|
|
32
|
+
opacity: var(--dc-disabled-state-opacity);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
.dc-token-input[data-invalid="true"] {
|
|
36
|
+
border-color: var(--border-color-error);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
.dc-token-input:focus-within {
|
|
40
|
+
border-color: var(--focus-ring-color);
|
|
41
|
+
box-shadow: 0 0 0 1px var(--focus-ring-color);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
.dc-token-input_size_sm {
|
|
45
|
+
--input-padding: 0 5px;
|
|
46
|
+
--token-height: 24px;
|
|
47
|
+
--token-padding: 0 0 0 8px;
|
|
48
|
+
--token-border-radius: 2px;
|
|
49
|
+
|
|
50
|
+
gap: 3px;
|
|
51
|
+
min-height: 32px;
|
|
52
|
+
padding: 3px;
|
|
53
|
+
font-size: 13px;
|
|
54
|
+
border-radius: 6px;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
.dc-token-input_size_lg {
|
|
58
|
+
--input-padding: 0 12px;
|
|
59
|
+
--token-height: 30px;
|
|
60
|
+
--token-padding: 0 0 0 12px;
|
|
61
|
+
--token-border-radius: 3px;
|
|
62
|
+
|
|
63
|
+
gap: 4px;
|
|
64
|
+
min-height: 40px;
|
|
65
|
+
padding: 4px;
|
|
66
|
+
font-size: 15px;
|
|
67
|
+
border-radius: 8px;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
.dc-token-input > input {
|
|
71
|
+
flex-grow: 1;
|
|
72
|
+
width: auto;
|
|
73
|
+
min-width: 10ch;
|
|
74
|
+
padding: var(--input-padding);
|
|
75
|
+
font: inherit;
|
|
76
|
+
line-height: 1.5;
|
|
77
|
+
background: none;
|
|
78
|
+
border: none;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
.dc-token-input > input::-moz-placeholder {
|
|
82
|
+
color: inherit;
|
|
83
|
+
opacity: 0.4;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
.dc-token-input > input::placeholder {
|
|
87
|
+
color: inherit;
|
|
88
|
+
opacity: 0.4;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
.dc-token-input > input:not(:only-child) {
|
|
92
|
+
padding-right: 0.25em;
|
|
93
|
+
padding-left: 0.25em;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
.dc-token-input > input:focus {
|
|
97
|
+
outline: none;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
.dc-token-input__token {
|
|
101
|
+
display: inline-flex;
|
|
102
|
+
gap: 2px;
|
|
103
|
+
max-width: 100%;
|
|
104
|
+
min-height: var(--token-height);
|
|
105
|
+
padding: var(--token-padding);
|
|
106
|
+
font: inherit;
|
|
107
|
+
color: var(--token-color);
|
|
108
|
+
cursor: default;
|
|
109
|
+
background: var(--token-background);
|
|
110
|
+
border-radius: var(--token-border-radius);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
.dc-token-input__token > span {
|
|
114
|
+
padding: calc((var(--token-height) - 20px) / 2) 0;
|
|
115
|
+
line-height: 20px;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
.dc-token-input__token > button {
|
|
119
|
+
display: inline-flex;
|
|
120
|
+
flex-shrink: 0;
|
|
121
|
+
align-items: center;
|
|
122
|
+
justify-content: center;
|
|
123
|
+
width: var(--token-height);
|
|
124
|
+
height: var(--token-height);
|
|
125
|
+
padding: 0;
|
|
126
|
+
font: inherit;
|
|
127
|
+
line-height: 1;
|
|
128
|
+
color: inherit;
|
|
129
|
+
-webkit-appearance: none;
|
|
130
|
+
-moz-appearance: none;
|
|
131
|
+
appearance: none;
|
|
132
|
+
cursor: default;
|
|
133
|
+
background: none;
|
|
134
|
+
border: none;
|
|
135
|
+
border-radius: inherit;
|
|
136
|
+
opacity: 0.5;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
.dc-token-input__token > button:focus {
|
|
140
|
+
outline: none;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
.dc-token-input__token > button:not(:disabled):hover,
|
|
144
|
+
.dc-token-input__token > button:not(:disabled):focus-visible {
|
|
145
|
+
background: var(--token-background-hover);
|
|
146
|
+
opacity: 1;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
.dark .dc-token-input,
|
|
150
|
+
.dark.dc-token-input {
|
|
151
|
+
--color: var(--dc-white);
|
|
152
|
+
--background: var(--dc-neutral-800);
|
|
153
|
+
--border-color: var(--dc-neutral-600);
|
|
154
|
+
--border-color-error: var(--dc-red-400);
|
|
155
|
+
--token-color: var(--dc-white);
|
|
156
|
+
--token-background: var(--dc-neutral-600);
|
|
157
|
+
--token-background-hover: rgb(var(--dc-neutral-50-rgb) / 15%);
|
|
158
|
+
|
|
159
|
+
color-scheme: dark;
|
|
160
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type ComponentProps, type CSSProperties } from 'react';
|
|
2
|
+
type HTMLInputProps = ComponentProps<'input'>;
|
|
3
|
+
export type TokenInputSize = 'sm' | 'md' | 'lg';
|
|
4
|
+
export type TokenInputChangeHandler = (tokens: string[]) => void;
|
|
5
|
+
export type TokenInputGetRemoveButtonAriaLabel = (token: string) => string;
|
|
6
|
+
export type TokenInputProps = {
|
|
7
|
+
id?: string;
|
|
8
|
+
style?: CSSProperties;
|
|
9
|
+
className?: string;
|
|
10
|
+
size?: TokenInputSize;
|
|
11
|
+
ariaLabel?: string;
|
|
12
|
+
placeholder?: string;
|
|
13
|
+
defaultValue?: string;
|
|
14
|
+
inputMode?: HTMLInputProps['inputMode'];
|
|
15
|
+
autoComplete?: HTMLInputProps['autoComplete'];
|
|
16
|
+
invalid?: boolean;
|
|
17
|
+
disabled?: boolean;
|
|
18
|
+
allowDuplicateTokens?: boolean;
|
|
19
|
+
tokens: string[];
|
|
20
|
+
onChange: TokenInputChangeHandler;
|
|
21
|
+
getRemoveButtonAriaLabel?: TokenInputGetRemoveButtonAriaLabel;
|
|
22
|
+
};
|
|
23
|
+
export declare function TokenInput({ id: defaultInputId, style, className, size, ariaLabel, placeholder, defaultValue, inputMode, autoComplete, invalid, disabled, allowDuplicateTokens, tokens, onChange, getRemoveButtonAriaLabel, }: TokenInputProps): import("react/jsx-runtime").JSX.Element;
|
|
24
|
+
export {};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useId, } from 'react';
|
|
3
|
+
import { classNames } from '../../lib/react-helpers.js';
|
|
4
|
+
export function TokenInput({ id: defaultInputId, style, className, size, ariaLabel, placeholder, defaultValue, inputMode, autoComplete = 'off', invalid, disabled, allowDuplicateTokens, tokens, onChange, getRemoveButtonAriaLabel, }) {
|
|
5
|
+
const id = useId();
|
|
6
|
+
const inputId = defaultInputId || `${id}token-input`;
|
|
7
|
+
const focus = () => {
|
|
8
|
+
const input = document.getElementById(inputId);
|
|
9
|
+
if (input instanceof HTMLInputElement) {
|
|
10
|
+
input.focus();
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
const removeToken = (index) => {
|
|
14
|
+
if (!disabled && index >= 0 && index < tokens.length) {
|
|
15
|
+
const newTokens = [...tokens];
|
|
16
|
+
newTokens.splice(index, 1);
|
|
17
|
+
onChange(newTokens);
|
|
18
|
+
focus();
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
const handleKeyDown = (event) => {
|
|
22
|
+
const input = event.currentTarget;
|
|
23
|
+
if (event.key === 'Enter') {
|
|
24
|
+
if (input.value) {
|
|
25
|
+
if (allowDuplicateTokens || !tokens.includes(input.value)) {
|
|
26
|
+
onChange([...tokens, input.value]);
|
|
27
|
+
}
|
|
28
|
+
input.value = '';
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
if (event.key === 'Backspace') {
|
|
32
|
+
if (!input.value) {
|
|
33
|
+
onChange(tokens.slice(0, -1));
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
return (_jsxs("label", { style: style, className: classNames(className, {
|
|
38
|
+
'dc-token-input': true,
|
|
39
|
+
[`dc-token-input_size_${size}`]: size,
|
|
40
|
+
}), htmlFor: inputId, "data-invalid": invalid, "data-disabled": disabled, children: [tokens.map((token, index) => (_jsx(Token, { value: token, disabled: disabled, onRemove: () => removeToken(index), getRemoveButtonAriaLabel: getRemoveButtonAriaLabel }, token))), _jsx("input", { "aria-label": ariaLabel, placeholder: placeholder, id: inputId, defaultValue: defaultValue, inputMode: inputMode, autoComplete: autoComplete, disabled: disabled, onKeyDown: handleKeyDown })] }));
|
|
41
|
+
}
|
|
42
|
+
function Token({ value, disabled, onRemove, getRemoveButtonAriaLabel, }) {
|
|
43
|
+
const handleButtonClick = (event) => {
|
|
44
|
+
event.preventDefault();
|
|
45
|
+
event.stopPropagation();
|
|
46
|
+
onRemove();
|
|
47
|
+
};
|
|
48
|
+
let buttonAriaLabel;
|
|
49
|
+
if (typeof getRemoveButtonAriaLabel === 'function') {
|
|
50
|
+
buttonAriaLabel = getRemoveButtonAriaLabel(value);
|
|
51
|
+
}
|
|
52
|
+
return (_jsxs("div", { className: "dc-token-input__token", children: [_jsx("span", { children: value }), _jsx("button", { "aria-label": buttonAriaLabel, type: "button", disabled: disabled, onClick: handleButtonClick, children: _jsx(XMarkIcon, { width: "1em", height: "1em" }) })] }));
|
|
53
|
+
}
|
|
54
|
+
function XMarkIcon(props) {
|
|
55
|
+
return (_jsx("svg", { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", width: 24, height: 24, stroke: "currentColor", strokeWidth: 2, fill: "none", ...props, children: _jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M6 18 18 6M6 6l12 12" }) }));
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=token-input.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"token-input.js","sourceRoot":"","sources":["../../../src/components/token-input/token-input.tsx"],"names":[],"mappings":";AAAA,OAAO,EACL,KAAK,GAKN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