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