@northlight/ui 2.23.0 → 2.24.1

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.
@@ -32,7 +32,6 @@ import { Props as Props$1 } from 'react-input-mask';
32
32
  import { NumericFormatProps } from 'react-number-format';
33
33
  import { Schema } from 'joi';
34
34
  import { UseClickableProps } from '@chakra-ui/clickable';
35
- import { Option as Option$1 } from '@northlight/ui';
36
35
  import { Variant } from 'chakra-react-select/dist/types/types';
37
36
  import * as _react_types_shared from '@react-types/shared';
38
37
  import * as _react_aria_focus from '@react-aria/focus';
@@ -4135,7 +4134,7 @@ interface StepStackProps extends StackProps {
4135
4134
  */
4136
4135
  declare const StepStack: ({ children, spacing, rowHeight, stepCircleAlignment, stepCircleMarginTopPx, ...rest }: StepStackProps) => JSX.Element;
4137
4136
 
4138
- interface CreationOption extends Option$1 {
4137
+ interface CreationOption extends Option {
4139
4138
  isCreation: boolean;
4140
4139
  }
4141
4140
  interface CreatableSelectDropdownProps {
@@ -4143,12 +4142,12 @@ interface CreatableSelectDropdownProps {
4143
4142
  * An array of "Option" objects that represents the initial options available in the dropdown.
4144
4143
  * Each "Option" object must have a "label" and a "value" property (both strings).
4145
4144
  */
4146
- standardOptions: Option$1[];
4145
+ standardOptions: Option[];
4147
4146
  /**
4148
4147
  * A callback function that is called whenever the selected option changes.
4149
4148
  * This function receives the newly selected "Option" object as its only argument.
4150
4149
  */
4151
- onOptionChange: (option: Option$1) => void;
4150
+ onOptionChange: (option: Option) => void;
4152
4151
  /**
4153
4152
  * Optional placeholder text displayed when no option is selected and the dropdown is not focused.
4154
4153
  * Defaults to 'Select or create...' if not provided.
@@ -4178,6 +4177,10 @@ interface CreatableSelectDropdownProps {
4178
4177
  *
4179
4178
  */
4180
4179
  variant?: Variant;
4180
+ /**
4181
+ * Value of the initially selected option.
4182
+ */
4183
+ initialValue?: string;
4181
4184
  }
4182
4185
 
4183
4186
  /**
@@ -4186,36 +4189,69 @@ interface CreatableSelectDropdownProps {
4186
4189
  * @see {@link https://northlight.dev/reference/creatable-select-dropdown}
4187
4190
  *
4188
4191
  * @example (Example)
4189
- * ##Select the best artist
4190
4192
  * (?
4191
4193
  * () => {
4192
4194
  * const [artist, setArtist] = useState(null);
4193
- * const options = [
4195
+ * const [element, setElement] = useState({ label: 'Technique', value: 'technique' })
4196
+ * const someOptions = [
4194
4197
  * { label: 'Scooter', value: 'scooter' },
4195
4198
  * { label: 'Snoop Doggy Dogg', value: 'snoop-dogg' },
4196
4199
  * ];
4197
4200
  *
4198
- * const handleOptionChange = (newOption) => {
4199
- * setArtist(newOption);
4200
- * // Perform additional actions with the selected or created option
4201
- * };
4201
+ * const someOtherOptions = [
4202
+ * { label: 'Vision', value: 'vision' },
4203
+ * { label: 'Technique', value: 'technique' },
4204
+ * { label: 'Expression', value: 'expression' }
4205
+ * ];
4202
4206
  *
4203
4207
  * return (
4204
- * <Box align="left">
4205
- * <CreatableSelectDropdown
4206
- * standardOptions={options}
4207
- * onOptionChange={handleOptionChange}
4208
- * width="300px"
4209
- * />
4210
- * { artist && artist.value !== 'Add option...' && (
4211
- * <H3 py={8}>The best artist is: { artist.label }</H3>
4212
- * ) }
4213
- * </Box>
4208
+ * <VStack gap={10} alignItems={"flex-start"}>
4209
+ * <Box align="left">
4210
+ * <H1>Basic example</H1>
4211
+ * <H3>Select the best artist</H3>
4212
+ * <CreatableSelectDropdown
4213
+ * standardOptions={someOptions}
4214
+ * onOptionChange={setArtist}
4215
+ * width="300px"
4216
+ * />
4217
+ * {artist && artist.value !== 'Add option...' && (
4218
+ * <H3 py={8}>The best artist is: {artist.label}</H3>
4219
+ * )}
4220
+ * </Box>
4221
+ * <Box align="left">
4222
+ * <H1>Pre-selected option</H1>
4223
+ * <H3>What is the quintessential element of an exceptional artisan?</H3>
4224
+ * <CreatableSelectDropdown
4225
+ * standardOptions={someOtherOptions}
4226
+ * onOptionChange={setElement}
4227
+ * width="300px"
4228
+ * initialValue="technique"
4229
+ * />
4230
+ * {element && element.value !== 'Add option...' && (
4231
+ * <H3 py={8}>
4232
+ * {element.value === 'vision' && (
4233
+ * 'The artist\'s vision shapes their creative world.'
4234
+ * )}
4235
+ * {element.value === 'technique' && (
4236
+ * 'Technique is the legacy\'s bedrock.'
4237
+ * )}
4238
+ * {element.value === 'expression' && (
4239
+ * 'Expression communicates the artist\'s inner voice.'
4240
+ * )}
4241
+ * {element.value !== 'vision' &&
4242
+ * element.value !== 'technique' &&
4243
+ * element.value !== 'expression' && (
4244
+ * 'Absent the selection of legitimate alternatives.'
4245
+ * )}
4246
+ * </H3>
4247
+ * )}
4248
+ * </Box>
4249
+ * </VStack>
4214
4250
  * );
4215
4251
  * }
4216
4252
  * ?)
4217
4253
  */
4218
- declare const CreatableSelectDropdown: ({ standardOptions, initialPlaceholder, addOptionPlaceholder, creationOption, onOptionChange, width, variant, }: CreatableSelectDropdownProps) => JSX.Element;
4254
+ declare const CreatableSelectDropdown: ({ standardOptions, initialPlaceholder, addOptionPlaceholder, creationOption, onOptionChange, width, variant, initialValue, }: CreatableSelectDropdownProps) => JSX.Element;
4219
4255
 
4220
4256
  declare const useDebounce: <T>(value: T, delay: number) => T;
4221
4257
 
@@ -13811,7 +13811,7 @@ var __objRest = (source, exclude) => {
13811
13811
  const customComponents = {
13812
13812
  Option: (_a) => {
13813
13813
  var _b = _a, { children } = _b, props = __objRest(_b, ["children"]);
13814
- return /* @__PURE__ */ React.createElement(chakraComponents.Option, __spreadValues$1({}, props), /* @__PURE__ */ React.createElement(React.Fragment, null, props.data.isCreation ? /* @__PURE__ */ React.createElement(Flex, { mr: 3, width: 1.5, mb: 0.5, justifyContent: "center", alignItems: "center" }, /* @__PURE__ */ React.createElement(Icon$2, { mb: "4px", as: PlusSolid, color: "brand" })) : /* @__PURE__ */ React.createElement(Box, { mr: 3, width: 1.5 }), children));
13814
+ return /* @__PURE__ */ React.createElement(chakraComponents.Option, __spreadValues$1({}, props), /* @__PURE__ */ React.createElement(React.Fragment, null, props.data.isCreation ? /* @__PURE__ */ React.createElement(Flex, { mr: 3, width: 1.5, mb: 0.5, justifyContent: "center", alignItems: "center" }, /* @__PURE__ */ React.createElement(Icon$1, { mb: "4px", as: PlusSolid, color: "brand" })) : /* @__PURE__ */ React.createElement(Box, { mr: 3, width: 1.5 }), children));
13815
13815
  }
13816
13816
  };
13817
13817
 
@@ -13845,9 +13845,16 @@ const CreatableSelectDropdown = ({
13845
13845
  },
13846
13846
  onOptionChange,
13847
13847
  width = "100%",
13848
- variant = "outline"
13848
+ variant = "outline",
13849
+ initialValue = ""
13849
13850
  }) => {
13850
- const [selectedOption, setSelectedOption] = useState(null);
13851
+ const initialSelectedOption = useMemo(
13852
+ () => standardOptions.find(
13853
+ (option) => option.value === initialValue
13854
+ ) || null,
13855
+ []
13856
+ );
13857
+ const [selectedOption, setSelectedOption] = useState(initialSelectedOption);
13851
13858
  const [newOptionText, setNewOptionText] = useState("");
13852
13859
  const [newOptionPlaceholder, setNewOptionPlaceholder] = useState(initialPlaceholder);
13853
13860
  const [createdOptions, setCreatedOptions] = useState([]);
@@ -13869,7 +13876,8 @@ const CreatableSelectDropdown = ({
13869
13876
  function isCreationOption(option) {
13870
13877
  return option && typeof option.isCreation === "string";
13871
13878
  }
13872
- const handleChange = (option) => {
13879
+ const handleChange = (newValue, _actionMeta) => {
13880
+ const option = newValue;
13873
13881
  if (option === null) {
13874
13882
  return;
13875
13883
  }
@@ -13891,25 +13899,26 @@ const CreatableSelectDropdown = ({
13891
13899
  const combinedOptions = [...standardOptions, ...createdOptions];
13892
13900
  const customOptions = [
13893
13901
  __spreadProps(__spreadValues({}, creationOption), {
13894
- icon: /* @__PURE__ */ React.createElement(Icon$2, { as: PlusSolid, color: "brand" })
13902
+ icon: /* @__PURE__ */ React.createElement(Icon$1, { as: PlusSolid, color: "brand" })
13895
13903
  }),
13896
13904
  ...combinedOptions
13897
13905
  ];
13898
13906
  return /* @__PURE__ */ React.createElement(
13899
13907
  CreatableSelect,
13900
13908
  {
13901
- chakraStyles: {
13909
+ chakraStyles: __spreadProps(__spreadValues({}, customSelectStyles), {
13902
13910
  container: (provided) => __spreadProps(__spreadValues({}, provided), {
13903
13911
  width
13904
13912
  }),
13905
13913
  option: (provided, { isSelected }) => __spreadValues(__spreadValues({}, provided), isSelected && {
13906
13914
  color: "black"
13907
13915
  })
13908
- },
13916
+ }),
13909
13917
  components: customComponents,
13910
13918
  options: customOptions,
13911
13919
  value: selectedOption,
13912
13920
  onChange: handleChange,
13921
+ isMulti: false,
13913
13922
  onInputChange: handleInputChange,
13914
13923
  onKeyDown: handleKeyDown,
13915
13924
  onCreateOption: handleCreateOption,