powell-react 0.0.9 → 0.0.11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (173) hide show
  1. package/package.json +7 -2
  2. package/.storybook/main.ts +0 -28
  3. package/.storybook/preview.scss +0 -13
  4. package/.storybook/preview.tsx +0 -24
  5. package/rollup.config.mjs +0 -95
  6. package/src/components/Button/Button.scss +0 -43
  7. package/src/components/Button/Button.stories.tsx +0 -13
  8. package/src/components/Button/Button.tsx +0 -19
  9. package/src/components/Button/index.ts +0 -1
  10. package/src/components/index.ts +0 -1
  11. package/src/index.ts +0 -1
  12. package/src/powell/api/PowellProvider.tsx +0 -37
  13. package/src/powell/api/configService.ts +0 -4
  14. package/src/powell/api/forms.ts +0 -145
  15. package/src/powell/api/index.ts +0 -5
  16. package/src/powell/api/powellDefaults.ts +0 -11
  17. package/src/powell/api/primereact.ts +0 -1945
  18. package/src/powell/components/AutoComplete/AutoComplete.scss +0 -126
  19. package/src/powell/components/AutoComplete/AutoComplete.tsx +0 -190
  20. package/src/powell/components/AutoComplete/index.ts +0 -1
  21. package/src/powell/components/Button/Button.tsx +0 -90
  22. package/src/powell/components/Button/index.ts +0 -1
  23. package/src/powell/components/CascadeSelect/CascadeSelect.scss +0 -126
  24. package/src/powell/components/CascadeSelect/CascadeSelect.tsx +0 -190
  25. package/src/powell/components/CascadeSelect/index.ts +0 -1
  26. package/src/powell/components/Checkbox/Checkbox.scss +0 -32
  27. package/src/powell/components/Checkbox/Checkbox.tsx +0 -147
  28. package/src/powell/components/Checkbox/index.ts +0 -1
  29. package/src/powell/components/Chips/Chips.scss +0 -126
  30. package/src/powell/components/Chips/Chips.tsx +0 -190
  31. package/src/powell/components/Chips/index.ts +0 -1
  32. package/src/powell/components/ColorPicker/ColorPicker.scss +0 -126
  33. package/src/powell/components/ColorPicker/ColorPicker.tsx +0 -186
  34. package/src/powell/components/ColorPicker/index.ts +0 -1
  35. package/src/powell/components/Dropdown/Dropdown.scss +0 -126
  36. package/src/powell/components/Dropdown/Dropdown.tsx +0 -190
  37. package/src/powell/components/Dropdown/index.ts +0 -1
  38. package/src/powell/components/Editor/Editor.scss +0 -126
  39. package/src/powell/components/Editor/Editor.tsx +0 -183
  40. package/src/powell/components/Editor/index.ts +0 -1
  41. package/src/powell/components/FormContainer/FormContainer.tsx +0 -49
  42. package/src/powell/components/FormContainer/FormContext.tsx +0 -18
  43. package/src/powell/components/FormContainer/index.ts +0 -2
  44. package/src/powell/components/InputMask/InputMask.scss +0 -126
  45. package/src/powell/components/InputMask/InputMask.tsx +0 -190
  46. package/src/powell/components/InputMask/index.ts +0 -1
  47. package/src/powell/components/InputNumber/InputNumber.scss +0 -126
  48. package/src/powell/components/InputNumber/InputNumber.tsx +0 -190
  49. package/src/powell/components/InputNumber/index.ts +0 -1
  50. package/src/powell/components/InputOtp/InputOtp.scss +0 -126
  51. package/src/powell/components/InputOtp/InputOtp.tsx +0 -154
  52. package/src/powell/components/InputOtp/index.ts +0 -1
  53. package/src/powell/components/InputPassword/InputPassword.scss +0 -126
  54. package/src/powell/components/InputPassword/InputPassword.tsx +0 -189
  55. package/src/powell/components/InputPassword/index.ts +0 -1
  56. package/src/powell/components/InputSwitch/InputSwitch.scss +0 -32
  57. package/src/powell/components/InputSwitch/InputSwitch.tsx +0 -144
  58. package/src/powell/components/InputSwitch/index.ts +0 -1
  59. package/src/powell/components/InputText/InputText.scss +0 -126
  60. package/src/powell/components/InputText/InputText.tsx +0 -190
  61. package/src/powell/components/InputText/index.ts +0 -1
  62. package/src/powell/components/InputTextarea/InputTextarea.scss +0 -126
  63. package/src/powell/components/InputTextarea/InputTextarea.tsx +0 -187
  64. package/src/powell/components/InputTextarea/index.ts +0 -1
  65. package/src/powell/components/Knob/Knob.scss +0 -32
  66. package/src/powell/components/Knob/Knob.tsx +0 -134
  67. package/src/powell/components/Knob/index.ts +0 -1
  68. package/src/powell/components/ListBox/ListBox.scss +0 -32
  69. package/src/powell/components/ListBox/ListBox.tsx +0 -135
  70. package/src/powell/components/ListBox/index.ts +0 -1
  71. package/src/powell/components/Mention/Mention.scss +0 -126
  72. package/src/powell/components/Mention/Mention.tsx +0 -186
  73. package/src/powell/components/Mention/index.ts +0 -1
  74. package/src/powell/components/MultiSelect/MultiSelect.scss +0 -126
  75. package/src/powell/components/MultiSelect/MultiSelect.tsx +0 -190
  76. package/src/powell/components/MultiSelect/index.ts +0 -1
  77. package/src/powell/components/MultiStateCheckbox/MultiStateCheckbox.scss +0 -32
  78. package/src/powell/components/MultiStateCheckbox/MultiStateCheckbox.tsx +0 -143
  79. package/src/powell/components/MultiStateCheckbox/index.ts +0 -1
  80. package/src/powell/components/RadioGroup/RadioGroup.scss +0 -32
  81. package/src/powell/components/RadioGroup/RadioGroup.tsx +0 -167
  82. package/src/powell/components/RadioGroup/index.ts +0 -1
  83. package/src/powell/components/Rating/Rating.scss +0 -32
  84. package/src/powell/components/Rating/Rating.tsx +0 -135
  85. package/src/powell/components/Rating/index.ts +0 -1
  86. package/src/powell/components/SelectButton/SelectButton.scss +0 -32
  87. package/src/powell/components/SelectButton/SelectButton.tsx +0 -144
  88. package/src/powell/components/SelectButton/index.ts +0 -1
  89. package/src/powell/components/Slider/Slider.scss +0 -32
  90. package/src/powell/components/Slider/Slider.tsx +0 -135
  91. package/src/powell/components/Slider/index.ts +0 -1
  92. package/src/powell/components/ToggleButton/ToggleButton.scss +0 -32
  93. package/src/powell/components/ToggleButton/ToggleButton.tsx +0 -144
  94. package/src/powell/components/ToggleButton/index.ts +0 -1
  95. package/src/powell/components/TreeSelect/TreeSelect.scss +0 -126
  96. package/src/powell/components/TreeSelect/TreeSelect.tsx +0 -190
  97. package/src/powell/components/TreeSelect/index.ts +0 -1
  98. package/src/powell/components/TriStateCheckbox/TriStateCheckbox.scss +0 -32
  99. package/src/powell/components/TriStateCheckbox/TriStateCheckbox.tsx +0 -144
  100. package/src/powell/components/TriStateCheckbox/index.ts +0 -1
  101. package/src/powell/hooks/index.ts +0 -3
  102. package/src/powell/hooks/useApplyConfig.ts +0 -36
  103. package/src/powell/hooks/useFormContext.ts +0 -14
  104. package/src/powell/hooks/usePowellConfig.ts +0 -64
  105. package/src/powell/index.ts +0 -29
  106. package/src/powell/models/common.ts +0 -7
  107. package/src/powell/models/config.ts +0 -85
  108. package/src/powell/models/forms.ts +0 -33
  109. package/src/powell/models/index.ts +0 -3
  110. package/src/powell/styles/common.scss +0 -9
  111. package/src/powell/styles/mixins.scss +0 -0
  112. package/src/powell/themes/arya-blue.css +0 -1
  113. package/src/powell/themes/arya-green.css +0 -1
  114. package/src/powell/themes/arya-orange.css +0 -1
  115. package/src/powell/themes/arya-purple.css +0 -1
  116. package/src/powell/themes/bootstrap4-dark-blue.css +0 -1
  117. package/src/powell/themes/bootstrap4-dark-purple.css +0 -1
  118. package/src/powell/themes/bootstrap4-light-blue.css +0 -1
  119. package/src/powell/themes/bootstrap4-light-purple.css +0 -1
  120. package/src/powell/themes/fluent-light.css +0 -1
  121. package/src/powell/themes/lara-dark-amber.css +0 -1
  122. package/src/powell/themes/lara-dark-blue.css +0 -1
  123. package/src/powell/themes/lara-dark-cyan.css +0 -1
  124. package/src/powell/themes/lara-dark-green.css +0 -1
  125. package/src/powell/themes/lara-dark-indigo.css +0 -1
  126. package/src/powell/themes/lara-dark-pink.css +0 -1
  127. package/src/powell/themes/lara-dark-purple.css +0 -1
  128. package/src/powell/themes/lara-dark-teal.css +0 -1
  129. package/src/powell/themes/lara-light-amber.css +0 -1
  130. package/src/powell/themes/lara-light-blue.css +0 -1
  131. package/src/powell/themes/lara-light-cyan.css +0 -1
  132. package/src/powell/themes/lara-light-green.css +0 -1
  133. package/src/powell/themes/lara-light-indigo.css +0 -1
  134. package/src/powell/themes/lara-light-pink.css +0 -1
  135. package/src/powell/themes/lara-light-purple.css +0 -1
  136. package/src/powell/themes/lara-light-teal.css +0 -1
  137. package/src/powell/themes/luna-amber.css +0 -1
  138. package/src/powell/themes/luna-blue.css +0 -1
  139. package/src/powell/themes/luna-green.css +0 -1
  140. package/src/powell/themes/luna-pink.css +0 -1
  141. package/src/powell/themes/md-dark-deeppurple.css +0 -1
  142. package/src/powell/themes/md-dark-indigo.css +0 -1
  143. package/src/powell/themes/md-light-deeppurple.css +0 -1
  144. package/src/powell/themes/md-light-indigo.css +0 -1
  145. package/src/powell/themes/mdc-dark-deeppurple.css +0 -1
  146. package/src/powell/themes/mdc-dark-indigo.css +0 -1
  147. package/src/powell/themes/mdc-light-deeppurple.css +0 -1
  148. package/src/powell/themes/mdc-light-indigo.css +0 -1
  149. package/src/powell/themes/mira.css +0 -1
  150. package/src/powell/themes/nano.css +0 -1
  151. package/src/powell/themes/nova-accent.css +0 -1
  152. package/src/powell/themes/nova-alt.css +0 -1
  153. package/src/powell/themes/nova.css +0 -1
  154. package/src/powell/themes/rhea.css +0 -1
  155. package/src/powell/themes/saga-blue.css +0 -1
  156. package/src/powell/themes/saga-green.css +0 -1
  157. package/src/powell/themes/saga-orange.css +0 -1
  158. package/src/powell/themes/saga-purple.css +0 -1
  159. package/src/powell/themes/soho-dark.css +0 -1
  160. package/src/powell/themes/soho-light.css +0 -1
  161. package/src/powell/themes/tailwind-light.css +0 -1
  162. package/src/powell/themes/vela-blue.css +0 -1
  163. package/src/powell/themes/vela-green.css +0 -1
  164. package/src/powell/themes/vela-orange.css +0 -1
  165. package/src/powell/themes/vela-purple.css +0 -1
  166. package/src/powell/themes/viva-dark.css +0 -1
  167. package/src/powell/themes/viva-light.css +0 -1
  168. package/src/powell/utils/globalState.ts +0 -96
  169. package/src/powell/utils/index.ts +0 -2
  170. package/src/powell/utils/utilsService.tsx +0 -55
  171. package/src/stories/Button.stories.tsx +0 -16
  172. package/tsconfig.json +0 -55
  173. package/vite.config.ts +0 -14
@@ -1,190 +0,0 @@
1
- import {ChangeEvent, ReactNode, useCallback, useRef, useState} from "react";
2
- import {Addon, LabelPosition, Size} from "@powell/models";
3
- import {
4
- $CascadeSelect,
5
- $CascadeSelectProps,
6
- $classNames,
7
- $ErrorMessage,
8
- $Field,
9
- $FieldProps,
10
- $FloatLabel,
11
- $IconField,
12
- $IconFieldProps,
13
- $InputIcon,
14
- $UniqueComponentId
15
- } from "@powell/api";
16
- import {getAddonTemplate, isRequiredField, transformer} from "@powell/utils";
17
- import {useApplyConfig, useFormContext} from "@powell/hooks";
18
- import {SafeAny} from "@powell/models";
19
- import '@components/CascadeSelect/CascadeSelect.scss';
20
-
21
- interface CascadeSelectProps extends $CascadeSelectProps {
22
- name?: string;
23
- parseError?: (error: string) => ReactNode;
24
- transform?: {
25
- input?: (value: SafeAny) => string;
26
- output?: (event: ChangeEvent<HTMLInputElement>) => SafeAny;
27
- };
28
- showRequiredStar?: boolean;
29
- rtl?: boolean;
30
- label?: string;
31
- icon?: string | ReactNode;
32
- hint?: string;
33
- addon?: Addon;
34
- inputSize?: Size;
35
- iconPosition?: $IconFieldProps["iconPosition"];
36
- labelPosition?: LabelPosition;
37
- }
38
-
39
- export const CascadeSelect = (props: CascadeSelectProps) => {
40
- props = useApplyConfig(props);
41
- const {
42
- parseError,
43
- name,
44
- transform = {},
45
- iconPosition = 'left',
46
- labelPosition,
47
- addon,
48
- icon,
49
- rtl,
50
- showRequiredStar,
51
- variant,
52
- inputSize,
53
- ...rest
54
- } = props;
55
-
56
- const inputId = useRef($UniqueComponentId());
57
-
58
- // Check if we're in Formik context
59
- const formContext = useFormContext();
60
- const withinForm = !!formContext && !!name;
61
- const isRequired = withinForm && isRequiredField(formContext, name);
62
-
63
- // Internal state for non-Formik usage
64
- const [internalValue, setInternalValue] = useState(rest.value || '');
65
-
66
- const inputEl = useCallback(() => {
67
- const commonProps = {
68
- ...rest,
69
- variant,
70
- id: inputId.current,
71
- name,
72
- };
73
-
74
- if (withinForm) {
75
- // if in Formik context
76
- return (
77
- <$Field name={name}>
78
- {({field, meta}: $FieldProps) => {
79
- const {value, onChange} = transformer({
80
- value: field.value,
81
- onChange: (event: string) => formContext.setFieldValue(name, event),
82
- transform: {
83
- input: transform.input ?? (value => value),
84
- output: transform.output ?? (event => event.value)
85
- }
86
- });
87
-
88
- return (
89
- <>
90
- <$CascadeSelect
91
- {...commonProps}
92
- value={value}
93
- onChange={(event) => {
94
- onChange(event);
95
- rest.onChange?.(event);
96
- }}
97
- onBlur={(event) => {
98
- field.onBlur(event);
99
- rest.onBlur?.(event);
100
- }}
101
- invalid={!!meta.error}
102
- />
103
- <$ErrorMessage name={name}>
104
- {
105
- (message) => <small className="error">{parseError?.(message) ?? message}</small>
106
- }
107
- </$ErrorMessage>
108
- <small className="hint">{rest.hint}</small>
109
- </>
110
- );
111
- }}
112
- </$Field>
113
- );
114
- } else {
115
- // if outside Formik context
116
- const {value, onChange} = transformer({
117
- value: internalValue,
118
- onChange: (event: string) => setInternalValue(event),
119
- transform: {
120
- input: transform.input ?? (value => value),
121
- output: transform.output ?? (event => event.value)
122
- }
123
- });
124
-
125
- return (
126
- <$CascadeSelect
127
- {...commonProps}
128
- value={value}
129
- onChange={(event) => {
130
- onChange(event);
131
- rest.onChange?.(event);
132
- }}
133
- onBlur={rest.onBlur}
134
- />
135
- );
136
- }
137
- }, [internalValue]);
138
-
139
- const labelEl = rest.label && (
140
- <label htmlFor={inputId.current}>
141
- {rest.label}
142
- {isRequired && showRequiredStar ? '*' : ''}
143
- </label>
144
- );
145
-
146
- const iconEl = icon && (
147
- typeof icon === 'string'
148
- ? <$InputIcon className={icon}></$InputIcon>
149
- : <$InputIcon>{icon}</$InputIcon>
150
- );
151
-
152
- const withIcon = (
153
- <$IconField iconPosition={iconPosition}>
154
- {iconEl}
155
- {inputEl()}
156
- </$IconField>
157
- );
158
-
159
- return (
160
- <div className={$classNames('cascade-select-wrapper',
161
- `variant-${variant}`,
162
- `p-inputtext-${inputSize}`,
163
- {
164
- [`label-${labelPosition}`]: rest.label,
165
- [`icon-${iconPosition}`]: iconEl,
166
- 'is-rtl': rtl,
167
- 'is-ltr': !rtl,
168
- 'addon-before': addon?.before,
169
- 'addon-after': addon?.after,
170
- })}>
171
- <div className="field">
172
- {labelPosition !== 'float' && labelEl}
173
- <div className={$classNames({"p-inputgroup": addon})}>
174
- {getAddonTemplate(addon?.before)}
175
- {
176
- labelPosition === 'float' ? (
177
- <$FloatLabel>
178
- {icon ? withIcon : inputEl()}
179
- {labelEl}
180
- </$FloatLabel>
181
- ) : (
182
- icon ? withIcon : inputEl()
183
- )
184
- }
185
- {getAddonTemplate(addon?.after)}
186
- </div>
187
- </div>
188
- </div>
189
- );
190
- };
@@ -1 +0,0 @@
1
- export * from "./CascadeSelect";
@@ -1,32 +0,0 @@
1
- .checkbox-wrapper {
2
- .field {
3
- display: flex;
4
- gap: 0.25rem 1rem;
5
-
6
- > .field-inner {
7
- flex-grow: 1;
8
- display: flex;
9
- }
10
- }
11
-
12
- &.label-fix-side .field {
13
- flex-direction: row;
14
- align-items: center;
15
- }
16
-
17
- &.label-fix-top .field {
18
- flex-direction: column;
19
-
20
- label {
21
- margin-bottom: 0.25rem;
22
- }
23
- }
24
-
25
- &.is-ltr {
26
- direction: ltr;
27
- }
28
-
29
- &.is-rtl {
30
- direction: rtl;
31
- }
32
- }
@@ -1,147 +0,0 @@
1
- import {ChangeEvent, ReactNode, useCallback, useRef, useState} from "react";
2
- import {FixLabelPosition} from "@powell/models";
3
- import {
4
- $Checkbox,
5
- $CheckboxProps,
6
- $classNames,
7
- $ErrorMessage,
8
- $Field,
9
- $FieldProps,
10
- $UniqueComponentId
11
- } from "@powell/api";
12
- import {isRequiredField, transformer} from "@powell/utils";
13
- import {useApplyConfig, useFormContext} from "@powell/hooks";
14
- import {SafeAny} from "@powell/models";
15
- import '@components/Checkbox/Checkbox.scss';
16
-
17
- interface CheckboxProps extends Omit<$CheckboxProps, 'checked'> {
18
- checked?: boolean;
19
- name?: string;
20
- parseError?: (error: string) => ReactNode;
21
- transform?: {
22
- input?: (value: SafeAny) => string;
23
- output?: (event: ChangeEvent<HTMLInputElement>) => SafeAny;
24
- };
25
- showRequiredStar?: boolean;
26
- rtl?: boolean;
27
- label?: string;
28
- hint?: string;
29
- labelPosition?: FixLabelPosition;
30
- }
31
-
32
- export const Checkbox = (props: CheckboxProps) => {
33
- props = useApplyConfig(props, {sizable: false, isFixLabel: true});
34
- const {
35
- parseError,
36
- name,
37
- transform = {},
38
- labelPosition,
39
- rtl,
40
- showRequiredStar,
41
- variant,
42
- ...rest
43
- } = props;
44
-
45
- const inputId = useRef($UniqueComponentId());
46
-
47
- // Check if we're in Formik context
48
- const formContext = useFormContext();
49
- const withinForm = !!formContext && !!name;
50
- const isRequired = withinForm && isRequiredField(formContext, name);
51
-
52
- // Internal state for non-Formik usage
53
- const [internalValue, setInternalValue] = useState(rest.checked ?? false);
54
-
55
- const rootEl = useCallback(() => {
56
- const commonProps = {
57
- ...rest,
58
- variant,
59
- inputId: inputId.current,
60
- name,
61
- };
62
-
63
- if (withinForm) {
64
- // if in Formik context
65
- return (
66
- <$Field name={name}>
67
- {({field, meta}: $FieldProps) => {
68
- const {value, onChange} = transformer({
69
- value: field.value,
70
- onChange: (event: boolean) => formContext.setFieldValue(name, event),
71
- transform: {
72
- input: transform.input ?? (value => value),
73
- output: transform.output ?? (event => event.checked)
74
- }
75
- });
76
-
77
- return (
78
- <>
79
- <$Checkbox
80
- {...commonProps}
81
- checked={value}
82
- onChange={(event) => {
83
- onChange(event);
84
- rest.onChange?.(event);
85
- }}
86
- invalid={!!meta.error}
87
- />
88
- <$ErrorMessage name={name}>
89
- {
90
- (message) => <small className="error">{parseError?.(message) ?? message}</small>
91
- }
92
- </$ErrorMessage>
93
- <small className="hint">{rest.hint}</small>
94
- </>
95
- );
96
- }}
97
- </$Field>
98
- );
99
- } else {
100
- // if outside Formik context
101
- const {value, onChange} = transformer({
102
- value: internalValue,
103
- onChange: (event: boolean) => setInternalValue(event),
104
- transform: {
105
- input: transform.input ?? (value => value),
106
- output: transform.output ?? (event => event.checked)
107
- }
108
- });
109
-
110
- return (
111
- <$Checkbox
112
- {...commonProps}
113
- checked={value}
114
- onChange={(event) => {
115
- onChange(event);
116
- rest.onChange?.(event);
117
- }}
118
- onBlur={rest.onBlur}
119
- />
120
- );
121
- }
122
- }, [internalValue, props]);
123
-
124
- const labelEl = rest.label && (
125
- <label htmlFor={inputId.current}>
126
- {rest.label}
127
- {isRequired && showRequiredStar ? '*' : ''}
128
- </label>
129
- );
130
-
131
- return (
132
- <div className={$classNames('checkbox-wrapper',
133
- `variant-${variant}`,
134
- {
135
- [`label-${labelPosition}`]: rest.label,
136
- 'is-rtl': rtl,
137
- 'is-ltr': !rtl,
138
- })}>
139
- <div className="field">
140
- {labelEl}
141
- <div className={$classNames('field-inner')}>
142
- {rootEl()}
143
- </div>
144
- </div>
145
- </div>
146
- );
147
- };
@@ -1 +0,0 @@
1
- export * from "./Checkbox";
@@ -1,126 +0,0 @@
1
- .chips-wrapper {
2
- .field {
3
- display: flex;
4
- gap: 0.25rem 1rem;
5
-
6
- > .field-inner {
7
- flex-grow: 1;
8
- }
9
- }
10
-
11
- :where(.p-inputtext, .p-chips) {
12
- width: 100%;
13
- }
14
-
15
- .p-icon-field {
16
- .p-input-icon {
17
- z-index: 5;
18
- color: var(--text-color-secondary);
19
- }
20
-
21
- &.p-icon-field-right {
22
- :where(.p-inputtext) {
23
- padding-right: 2.5rem;
24
- }
25
-
26
- .p-input-icon {
27
- right: 0.75rem;
28
- left: auto;
29
- }
30
- }
31
-
32
- &.p-icon-field-left {
33
- :where(.p-inputtext) {
34
- padding-left: 2.5rem;
35
- }
36
-
37
- .p-input-icon {
38
- left: 0.75rem;
39
- right: auto;
40
- }
41
- }
42
- }
43
-
44
- &.label-fix-side .field {
45
- flex-direction: row;
46
- align-items: center;
47
- }
48
-
49
- &.label-fix-top .field {
50
- flex-direction: column;
51
-
52
- label {
53
- margin-bottom: 0.25rem;
54
- }
55
- }
56
-
57
- &.addon-before {
58
- [class*="icon-"] {
59
- :where(.p-inputtext, .p-chips) {
60
- border-radius: 0 var(--border-radius) var(--border-radius) 0;
61
- }
62
- }
63
- }
64
-
65
- &.addon-after {
66
- &.label-float {
67
- .p-inputgroup-addon {
68
- border-left: 0;
69
- }
70
- }
71
-
72
- [class*="icon-"] {
73
- :where(.p-inputtext, .p-chips) {
74
- border-radius: var(--border-radius) 0 0 var(--border-radius);
75
- }
76
- }
77
- }
78
-
79
- &[class*="addon-"] {
80
- .p-inputgroup {
81
- .p-icon-field,
82
- .p-float-label {
83
- flex-grow: 1;
84
- }
85
- }
86
-
87
- &.addon-before :where(.p-inputtext, .p-chips) {
88
- border-radius: 0 var(--border-radius) var(--border-radius) 0;
89
- }
90
-
91
- &.addon-after :where(.p-inputtext, .p-chips) {
92
- border-radius: var(--border-radius) 0 0 var(--border-radius);
93
- }
94
- }
95
-
96
- &.is-ltr {
97
- direction: ltr;
98
-
99
- &.label-float {
100
- &.icon-left .field label {
101
- left: 2.5rem;
102
- }
103
- }
104
- }
105
-
106
- &.is-rtl {
107
- direction: rtl;
108
-
109
- &.label-float {
110
- label {
111
- left: auto;
112
- right: 0.75rem;
113
- }
114
-
115
- &.icon-right .field label {
116
- right: 2.5rem;
117
- }
118
- }
119
-
120
- &[class*="addon-"] {
121
- .p-inputgroup {
122
- flex-direction: row-reverse;
123
- }
124
- }
125
- }
126
- }
@@ -1,190 +0,0 @@
1
- import {ReactNode, useCallback, useRef, useState} from "react";
2
- import {Addon, LabelPosition, SafeAny, Size} from "@powell/models";
3
- import {
4
- $Chips,
5
- $ChipsChangeEvent,
6
- $ChipsProps,
7
- $classNames,
8
- $ErrorMessage,
9
- $Field,
10
- $FieldProps,
11
- $FloatLabel,
12
- $IconField,
13
- $IconFieldProps,
14
- $InputIcon,
15
- $UniqueComponentId
16
- } from "@powell/api";
17
- import {getAddonTemplate, isRequiredField, transformer} from "@powell/utils";
18
- import {useApplyConfig, useFormContext} from "@powell/hooks";
19
- import '@components/Chips/Chips.scss';
20
-
21
- interface ChipsProps extends $ChipsProps {
22
- name?: string;
23
- parseError?: (error: string) => ReactNode;
24
- transform?: {
25
- input?: (value: SafeAny) => string;
26
- output?: (event: $ChipsChangeEvent) => SafeAny;
27
- };
28
- showRequiredStar?: boolean;
29
- rtl?: boolean;
30
- label?: string;
31
- icon?: string | ReactNode;
32
- hint?: string;
33
- inputSize?: Size;
34
- addon?: Addon;
35
- iconPosition?: $IconFieldProps["iconPosition"];
36
- labelPosition?: LabelPosition;
37
- }
38
-
39
- export const Chips = (props: ChipsProps) => {
40
- props = useApplyConfig(props);
41
- const {
42
- parseError,
43
- name,
44
- transform = {},
45
- iconPosition = 'left',
46
- labelPosition,
47
- addon,
48
- icon,
49
- rtl,
50
- showRequiredStar,
51
- variant,
52
- inputSize,
53
- ...rest
54
- } = props;
55
-
56
- const inputId = useRef($UniqueComponentId());
57
-
58
- // Check if we're in Formik context
59
- const formContext = useFormContext();
60
- const withinForm = !!formContext && !!name;
61
- const isRequired = withinForm && isRequiredField(formContext, name);
62
-
63
- // Internal state for non-Formik usage
64
- const [internalValue, setInternalValue] = useState(rest.value || []);
65
-
66
- const rootEl = useCallback(() => {
67
- const commonProps = {
68
- ...rest,
69
- variant,
70
- id: inputId.current,
71
- name,
72
- };
73
-
74
- if (withinForm) {
75
- // if in Formik context
76
- return (
77
- <$Field name={name}>
78
- {({field, meta}: $FieldProps) => {
79
- const {value, onChange} = transformer({
80
- value: field.value,
81
- onChange: (event: string[]) => formContext.setFieldValue(name, event),
82
- transform: {
83
- input: transform.input ?? (value => value),
84
- output: transform.output ?? (event => event.target.value)
85
- }
86
- });
87
-
88
- return (
89
- <>
90
- <$Chips
91
- {...commonProps}
92
- value={value}
93
- onChange={(event) => {
94
- onChange(event);
95
- rest.onChange?.(event);
96
- }}
97
- onBlur={(event) => {
98
- field.onBlur(event);
99
- rest.onBlur?.(event);
100
- }}
101
- invalid={!!meta.error}
102
- />
103
- <$ErrorMessage name={name}>
104
- {
105
- (message) => <small className="error">{parseError?.(message) ?? message}</small>
106
- }
107
- </$ErrorMessage>
108
- <small className="hint">{rest.hint}</small>
109
- </>
110
- );
111
- }}
112
- </$Field>
113
- );
114
- } else {
115
- // if outside Formik context
116
- const {value, onChange} = transformer<string[], $ChipsChangeEvent>({
117
- value: internalValue,
118
- onChange: (event: string[]) => setInternalValue(event),
119
- transform: {
120
- input: transform.input ?? (value => value),
121
- output: transform.output ?? (event => event.value)
122
- }
123
- });
124
-
125
- return (
126
- <$Chips
127
- {...commonProps}
128
- value={value}
129
- onChange={(event) => {
130
- onChange(event);
131
- rest.onChange?.(event);
132
- }}
133
- onBlur={rest.onBlur}
134
- />
135
- );
136
- }
137
- }, [internalValue, props]);
138
-
139
- const labelEl = rest.label && (
140
- <label htmlFor={inputId.current}>
141
- {rest.label}
142
- {isRequired && showRequiredStar ? '*' : ''}
143
- </label>
144
- );
145
-
146
- const iconEl = icon && (
147
- typeof icon === 'string'
148
- ? <$InputIcon className={icon}></$InputIcon>
149
- : <$InputIcon>{icon}</$InputIcon>
150
- );
151
-
152
- const withIcon = (
153
- <$IconField iconPosition={iconPosition}>
154
- {iconEl}
155
- {rootEl()}
156
- </$IconField>
157
- );
158
-
159
- return (
160
- <div className={$classNames('chips-wrapper',
161
- `variant-${variant}`,
162
- `p-inputtext-${inputSize}`,
163
- {
164
- [`label-${labelPosition}`]: rest.label,
165
- [`icon-${iconPosition}`]: iconEl,
166
- 'is-rtl': rtl,
167
- 'is-ltr': !rtl,
168
- 'addon-before': addon?.before,
169
- 'addon-after': addon?.after,
170
- })}>
171
- <div className="field">
172
- {labelPosition !== 'float' && labelEl}
173
- <div className={$classNames('field-inner', {"p-inputgroup": addon})}>
174
- {getAddonTemplate(addon?.before)}
175
- {
176
- labelPosition === 'float' ? (
177
- <$FloatLabel>
178
- {icon ? withIcon : rootEl()}
179
- {labelEl}
180
- </$FloatLabel>
181
- ) : (
182
- icon ? withIcon : rootEl()
183
- )
184
- }
185
- {getAddonTemplate(addon?.after)}
186
- </div>
187
- </div>
188
- </div>
189
- );
190
- };
@@ -1 +0,0 @@
1
- export * from "./Chips";