@sebgroup/green-react 3.2.0 → 3.4.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/README.md CHANGED
@@ -1,8 +1,12 @@
1
- # `@sebgroup/green-react`
1
+ <div align="center">
2
+ <img width="600" alt="green-react" src="https://github.com/sebgroup/green/assets/11420341/ad4c9fe3-137f-4230-9ea7-a4de87752aa9">
3
+ <h1>@sebgroup/green-react</h1>
4
+ <p>
5
+ React components with SEB's look and feel.
6
+ </p>
7
+ </div>
2
8
 
3
- > TODO: description
4
-
5
- ## Install \*
9
+ ## Install
6
10
 
7
11
  ```bash
8
12
  npm install --save @sebgroup/green-react
@@ -12,17 +16,18 @@ npm install --save @sebgroup/green-react
12
16
  yarn add @sebgroup/green-react
13
17
  ```
14
18
 
15
- ## Usage \*
19
+ ## Use
16
20
 
17
- ```
18
- const greenReact = require('@sebgroup/green-react');
21
+ ```tsx
22
+ import { Button } from '@sebgroup/green-react'
19
23
 
20
- // TODO: DEMONSTRATE API
24
+ // Use in your JSX
25
+ <Button>A Green React Button!</Button>
21
26
  ```
22
27
 
23
28
  ### Components
24
29
 
25
- View all components in the Storybook
30
+ View all components in the [React Storybook](https://sebgroup.github.io/green/latest/react/)
26
31
 
27
32
  ## Develop \*
28
33
 
@@ -57,5 +62,3 @@ yarn test react --watch
57
62
  1. Test
58
63
  2. Code
59
64
  3. Refactor
60
-
61
- ## Commands \*
package/index.esm.js CHANGED
@@ -1,8 +1,8 @@
1
1
  import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
2
- import React, { useState, useEffect, useMemo, useRef, useLayoutEffect, forwardRef, useCallback, useId } from 'react';
2
+ import React, { useState, useEffect, useRef, useLayoutEffect, useMemo, forwardRef, useCallback, useId } from 'react';
3
3
  import { randomId, validateClassName, debounce, delay, sliderColors, getSliderTrackBackground } from '@sebgroup/extract';
4
4
  import { createComponent } from '@lit/react';
5
- import { getScopedTagName, GdsDatepicker, GdsContextMenu, GdsMenuItem, GdsMenuHeading, GdsDropdown, GdsOption } from '@sebgroup/green-core';
5
+ import { getScopedTagName, GdsDatepicker, GdsContextMenu, GdsMenuItem, GdsMenuHeading, GdsDropdown, GdsOption, GdsGroupedList } from '@sebgroup/green-core';
6
6
  import { registerTransitionalStyles } from '@sebgroup/green-core/transitional-styles';
7
7
  import classNames from 'classnames';
8
8
 
@@ -2106,7 +2106,6 @@ const Datepicker = _a => {
2106
2106
  const min = minDate ? minDate : new Date(new Date().getFullYear() - 10, 0, 1);
2107
2107
  const max = maxDate ? maxDate : new Date(new Date().getFullYear() + 10, 0, 1);
2108
2108
  const onChangeHandler = e => {
2109
- console.log('OnChange event handler');
2110
2109
  if (onChange) {
2111
2110
  onChange(e.detail.value);
2112
2111
  }
@@ -2121,7 +2120,9 @@ const Datepicker = _a => {
2121
2120
  max: max,
2122
2121
  showWeekNumbers: showWeeks,
2123
2122
  onchange: onChangeHandler,
2124
- value: value
2123
+ size: props.size,
2124
+ value: value,
2125
+ hideLabel: props.hideLabel
2125
2126
  }, props))
2126
2127
  }));
2127
2128
  };
@@ -2294,23 +2295,25 @@ const CoreOption = createComponent({
2294
2295
  elementClass: GdsOption,
2295
2296
  react: React
2296
2297
  });
2297
- const Dropdown = ({
2298
- compareWith,
2299
- display: _display = 'label',
2300
- id,
2301
- informationLabel,
2302
- label,
2303
- multiSelect,
2304
- onChange,
2305
- options,
2306
- searchFilter,
2307
- searchable,
2308
- texts,
2309
- useValue: _useValue = 'value',
2310
- validator,
2311
- value,
2312
- syncPopoverWidth
2313
- }) => {
2298
+ const Dropdown = _a => {
2299
+ var {
2300
+ compareWith,
2301
+ display = 'label',
2302
+ id,
2303
+ informationLabel,
2304
+ label,
2305
+ multiSelect,
2306
+ onChange,
2307
+ options,
2308
+ searchFilter,
2309
+ searchable,
2310
+ texts,
2311
+ useValue = 'value',
2312
+ validator,
2313
+ value,
2314
+ syncPopoverWidth
2315
+ } = _a,
2316
+ props = __rest(_a, ["compareWith", "display", "id", "informationLabel", "label", "multiSelect", "onChange", "options", "searchFilter", "searchable", "texts", "useValue", "validator", "value", "syncPopoverWidth"]);
2314
2317
  const handleOnChange = e => {
2315
2318
  var _a;
2316
2319
  if ((_a = e.detail) === null || _a === void 0 ? void 0 : _a.value) {
@@ -2323,7 +2326,7 @@ const Dropdown = ({
2323
2326
  return compareFn(o1, o2);
2324
2327
  };
2325
2328
  const searchFilterAdapter = (q, o) => {
2326
- if (searchFilter) return searchFilter(q, o.value[_useValue]);else return ((q, o) => o.innerHTML.toLowerCase().includes(q.toLowerCase()))(q, o);
2329
+ if (searchFilter) return searchFilter(q, o.value[useValue]);else return ((q, o) => o.innerHTML.toLowerCase().includes(q.toLowerCase()))(q, o);
2327
2330
  };
2328
2331
  return jsx("div", Object.assign({
2329
2332
  className: "form-group"
@@ -2338,7 +2341,9 @@ const Dropdown = ({
2338
2341
  compareWith: compareWithAdapter,
2339
2342
  value: value,
2340
2343
  searchFilter: searchFilterAdapter,
2341
- syncPopoverWidth: syncPopoverWidth
2344
+ syncPopoverWidth: syncPopoverWidth,
2345
+ size: props.size,
2346
+ hideLabel: props.hideLabel
2342
2347
  }, {
2343
2348
  children: [informationLabel && jsx("span", Object.assign({
2344
2349
  slot: "sub-label"
@@ -2356,14 +2361,14 @@ const Dropdown = ({
2356
2361
  })), options.map(option => {
2357
2362
  if (option.heading) {
2358
2363
  return jsx(CoreMenuHeading, {
2359
- children: option[_display]
2364
+ children: option[display]
2360
2365
  }, option.label);
2361
2366
  }
2362
2367
  return jsx(CoreOption, Object.assign({
2363
- value: option[_useValue]
2368
+ value: option[useValue]
2364
2369
  }, {
2365
- children: option[_display]
2366
- }), option[_useValue]);
2370
+ children: option[display]
2371
+ }), option[useValue]);
2367
2372
  })]
2368
2373
  }))
2369
2374
  }));
@@ -2404,7 +2409,7 @@ const IconButton = _a => {
2404
2409
  } = _a,
2405
2410
  props = __rest(_a, ["children", "onClick"]);
2406
2411
  return jsx("button", Object.assign({
2407
- className: `icon ${props.size == 'small' && 'small'}`,
2412
+ className: `icon ${props.size === 'small' && 'small'}`,
2408
2413
  onClick: onClick,
2409
2414
  "aria-controls": props['aria-controls'],
2410
2415
  "aria-expanded": props['aria-expanded'],
@@ -2448,46 +2453,48 @@ const ButtonGroup = ({
2448
2453
  }));
2449
2454
  };
2450
2455
 
2451
- const useInput = (props, onChanges, onChangeInput) => {
2452
- const id = useMemo(() => props.id || randomId(), [props.id]);
2453
- const ref = useRef(null);
2454
- const onChange = event => {
2455
- onChanges && onChanges(event);
2456
- onChangeInput && onChangeInput(event.target.value);
2457
- };
2458
- return Object.assign(Object.assign({}, props), {
2459
- id,
2460
- ref,
2461
- onChange
2462
- });
2463
- };
2464
-
2465
2456
  const Checkbox = _a => {
2466
2457
  var {
2458
+ 'aria-describedby': ariaDescribedBy,
2459
+ id = randomId(),
2467
2460
  label,
2468
- onChange,
2469
2461
  validator,
2470
- testId
2462
+ testId,
2463
+ required,
2464
+ className
2471
2465
  } = _a,
2472
- props = __rest(_a, ["label", "onChange", "validator", "testId"]);
2473
- const inputProps = useInput(props, onChange);
2474
- const labelClassNames = classNames('form-control', validator && validateClassName(validator === null || validator === void 0 ? void 0 : validator.indicator));
2475
- const inputClassNames = classNames(validator && validateClassName(validator === null || validator === void 0 ? void 0 : validator.indicator));
2466
+ props = __rest(_a, ['aria-describedby', "id", "label", "validator", "testId", "required", "className"]);
2467
+ const [uuid] = useState(id);
2468
+ const validationClassName = validateClassName(validator === null || validator === void 0 ? void 0 : validator.indicator);
2469
+ const labelClassNames = classNames('form-control', {
2470
+ [validationClassName]: validator
2471
+ });
2472
+ const inputClassNames = classNames(className, {
2473
+ [validationClassName]: validator
2474
+ });
2475
+ const describedBy = classNames(ariaDescribedBy, {
2476
+ [`${uuid}_message`]: (validator === null || validator === void 0 ? void 0 : validator.message) !== undefined && validator.message.length > 0
2477
+ });
2476
2478
  return jsxs("div", Object.assign({
2477
2479
  className: "form-group"
2478
2480
  }, {
2479
2481
  children: [jsxs("label", Object.assign({
2480
- htmlFor: inputProps.id,
2482
+ htmlFor: uuid,
2481
2483
  className: labelClassNames
2482
2484
  }, {
2483
2485
  children: [label, jsx("input", Object.assign({
2486
+ "aria-describedby": describedBy || undefined,
2487
+ "aria-invalid": (validator === null || validator === void 0 ? void 0 : validator.indicator) === 'error',
2488
+ "aria-required": required,
2489
+ className: inputClassNames || undefined,
2484
2490
  type: "checkbox",
2485
- "data-testid": testId
2486
- }, inputProps, {
2487
- className: inputClassNames
2488
- })), jsx("i", {})]
2491
+ "data-testid": testId,
2492
+ id: uuid,
2493
+ required: required
2494
+ }, props)), jsx("i", {})]
2489
2495
  })), validator && jsx("span", Object.assign({
2490
- className: "form-info"
2496
+ className: "form-info",
2497
+ id: `${uuid}_message`
2491
2498
  }, {
2492
2499
  children: validator.message
2493
2500
  }))]
@@ -2707,7 +2714,8 @@ function Group({
2707
2714
  }, {
2708
2715
  children: children
2709
2716
  })), error && jsx("span", Object.assign({
2710
- className: "form-info"
2717
+ className: "form-info",
2718
+ id: id && `${id}-message`
2711
2719
  }, {
2712
2720
  children: errorMessage
2713
2721
  }))]
@@ -3912,7 +3920,8 @@ const FormItem = ({
3912
3920
  className: "gds-form-item__footer"
3913
3921
  }, {
3914
3922
  children: [validator && jsx("span", Object.assign({
3915
- className: "form-info"
3923
+ className: "form-info",
3924
+ id: `${inputId}_message`
3916
3925
  }, {
3917
3926
  children: validator.message
3918
3927
  })), rightAlignedFooterInfo && jsx("span", Object.assign({
@@ -3928,6 +3937,20 @@ const FormItem = ({
3928
3937
  }));
3929
3938
  };
3930
3939
 
3940
+ const useInput = (props, onChanges, onChangeInput) => {
3941
+ const id = useMemo(() => props.id || randomId(), [props.id]);
3942
+ const ref = useRef(null);
3943
+ const onChange = event => {
3944
+ onChanges && onChanges(event);
3945
+ onChangeInput && onChangeInput(event.target.value);
3946
+ };
3947
+ return Object.assign(Object.assign({}, props), {
3948
+ id,
3949
+ ref,
3950
+ onChange
3951
+ });
3952
+ };
3953
+
3931
3954
  const RadioButton = /*#__PURE__*/forwardRef((_a, ref) => {
3932
3955
  var {
3933
3956
  label,
@@ -3974,46 +3997,59 @@ const Input = _a => {
3974
3997
  role,
3975
3998
  validator,
3976
3999
  onChangeInput,
3977
- value = ''
4000
+ value = '',
4001
+ required
3978
4002
  } = _a,
3979
- props = __rest(_a, ['aria-describedby', "autoComplete", "children", "className", "testId", "expandableInfo", "expandableInfoButtonLabel", "formatter", "id", "label", "info", "onChange", "unit", "role", "validator", "onChangeInput", "value"]);
4003
+ props = __rest(_a, ['aria-describedby', "autoComplete", "children", "className", "testId", "expandableInfo", "expandableInfoButtonLabel", "formatter", "id", "label", "info", "onChange", "unit", "role", "validator", "onChangeInput", "value", "required"]);
3980
4004
  const [uuid] = useState(id);
3981
4005
  const [localValue, setLocalValue] = useState(value);
3982
4006
  useEffect(() => {
3983
4007
  setLocalValue(value);
3984
4008
  }, [value]);
3985
- const localOnChange = useCallback(event => {
3986
- const oldValue = event.target.value;
3987
- const newValue = formatter ? formatter(oldValue) : oldValue;
3988
- setLocalValue(newValue);
3989
- event.target.value = newValue;
3990
- if (onChange) onChange(event);
3991
- if (onChangeInput) onChangeInput(newValue);
4009
+ const handleChange = useCallback(event => {
4010
+ const {
4011
+ selectionStart,
4012
+ value
4013
+ } = event.target;
4014
+ const formattedValue = formatter ? formatter(value) : value;
4015
+ const nrAddedChars = formattedValue.length - value.length;
4016
+ const updateCaretPosition = nrAddedChars !== 0;
4017
+ const newSelectionStart = updateCaretPosition && selectionStart ? selectionStart + nrAddedChars : selectionStart;
3992
4018
  // Fixes bug: React loses caret position when you format the input value
3993
- if (!formatter || newValue.length > oldValue.length) return;
3994
- const pointer = event.target.selectionStart;
3995
- const element = event.target;
3996
4019
  window.requestAnimationFrame(() => {
3997
- element.selectionStart = pointer;
3998
- element.selectionEnd = pointer;
4020
+ event.target.selectionStart = newSelectionStart;
4021
+ event.target.selectionEnd = newSelectionStart;
3999
4022
  });
4023
+ setLocalValue(formattedValue);
4024
+ if (onChange) onChange(event);
4025
+ if (onChangeInput) onChangeInput(formattedValue);
4000
4026
  }, [formatter, setLocalValue, onChange, onChangeInput]);
4001
- const inputAriaDescribedBy = classNames(ariaDescribedBy, {
4002
- [`gds-expandable-info-${uuid}`]: expandableInfo,
4003
- [`${uuid}_info`]: info
4004
- }) || undefined;
4005
- const inputClassName = classNames(className, validator && validateClassName(validator.indicator)) || undefined;
4027
+ const showSimpleInput = !label && !info && !expandableInfo;
4028
+ const describedBy = classNames(ariaDescribedBy, {
4029
+ [`${uuid}_group-message`]: !showSimpleInput && (validator === null || validator === void 0 ? void 0 : validator.message) !== undefined && validator.message.length > 0,
4030
+ [`gds-expandable-info-${uuid}`]: !showSimpleInput && expandableInfo,
4031
+ [`${uuid}_info`]: !showSimpleInput && info
4032
+ });
4033
+ const inputClassName = classNames(className, {
4034
+ [validateClassName(validator === null || validator === void 0 ? void 0 : validator.indicator)]: validator
4035
+ });
4006
4036
  const input = jsx("input", Object.assign({
4007
- "aria-describedby": inputAriaDescribedBy,
4037
+ "aria-describedby": describedBy || undefined,
4038
+ "aria-invalid": (validator === null || validator === void 0 ? void 0 : validator.indicator) === 'error',
4039
+ "aria-required": required,
4008
4040
  autoComplete: autoComplete,
4009
- className: inputClassName,
4041
+ className: inputClassName || undefined,
4010
4042
  "data-testid": dataTestId,
4011
4043
  id: uuid,
4012
- onChange: localOnChange,
4044
+ onChange: handleChange,
4013
4045
  role: role,
4014
- value: localValue
4046
+ value: localValue,
4047
+ required: required
4015
4048
  }, props));
4016
- if (!label && !info && !expandableInfo) return input;
4049
+ if (showSimpleInput) return input;
4050
+ const spanClassName = classNames('form-text', {
4051
+ 'disabled': props.disabled
4052
+ });
4017
4053
  return jsx(FormItem, Object.assign({
4018
4054
  expandableInfo: expandableInfo,
4019
4055
  expandableInfoButtonLabel: expandableInfoButtonLabel,
@@ -4028,10 +4064,11 @@ const Input = _a => {
4028
4064
  children: jsxs(Group, Object.assign({
4029
4065
  groupBorder: true,
4030
4066
  groupFocus: true,
4031
- error: validator && validator.message
4067
+ error: validator === null || validator === void 0 ? void 0 : validator.message,
4068
+ id: `${uuid}_group`
4032
4069
  }, {
4033
4070
  children: [input, unit && jsx("span", Object.assign({
4034
- className: `form-text${props.disabled ? ' disabled' : ''}`
4071
+ className: spanClassName
4035
4072
  }, {
4036
4073
  children: unit
4037
4074
  })), children]
@@ -4214,23 +4251,27 @@ const TextArea = _a => {
4214
4251
  validator,
4215
4252
  value,
4216
4253
  testId: dataTestId,
4217
- maxLength
4254
+ maxLength,
4255
+ required
4218
4256
  } = _a,
4219
- props = __rest(_a, ['aria-describedby', "autoComplete", "className", "expandableInfo", "expandableInfoButtonLabel", "id", "label", "info", "onChange", "role", "rows", "validator", "value", "testId", "maxLength"]);
4257
+ props = __rest(_a, ['aria-describedby', "autoComplete", "className", "expandableInfo", "expandableInfoButtonLabel", "id", "label", "info", "onChange", "role", "rows", "validator", "value", "testId", "maxLength", "required"]);
4220
4258
  const [uuid] = useState(id);
4221
4259
  const [localValue, setLocalValue] = useState(value);
4222
4260
  useEffect(() => {
4223
4261
  setLocalValue(value);
4224
4262
  }, [value]);
4225
- const localOnChange = useCallback(event => {
4263
+ const handleChange = useCallback(event => {
4226
4264
  setLocalValue(event.target.value);
4227
4265
  if (onChange) onChange(event);
4228
4266
  }, [setLocalValue, onChange]);
4229
- const inputAriaDescribedBy = classNames(ariaDescribedBy, {
4267
+ const describedBy = classNames(ariaDescribedBy, {
4230
4268
  [`gds-expandable-info-${uuid}`]: expandableInfo,
4231
- [`${uuid}_info`]: info
4269
+ [`${uuid}_info`]: info,
4270
+ [`${uuid}_message`]: (validator === null || validator === void 0 ? void 0 : validator.message) !== undefined && validator.message.length > 0
4271
+ });
4272
+ const inputClassName = classNames(className, {
4273
+ [validateClassName(validator === null || validator === void 0 ? void 0 : validator.indicator)]: validator
4232
4274
  }) || undefined;
4233
- const inputClassName = classNames(className, validator && validateClassName(validator.indicator)) || undefined;
4234
4275
  const rightAlignedFooterInfo = maxLength ? `${(localValue === null || localValue === void 0 ? void 0 : localValue.length) || 0}/${maxLength}` : undefined;
4235
4276
  return jsx(FormItem, Object.assign({
4236
4277
  expandableInfo: expandableInfo,
@@ -4246,16 +4287,19 @@ const TextArea = _a => {
4246
4287
  className: "gds-input-wrapper"
4247
4288
  }, {
4248
4289
  children: jsx("textarea", Object.assign({
4249
- "aria-describedby": inputAriaDescribedBy,
4290
+ "aria-describedby": describedBy || undefined,
4291
+ "aria-invalid": (validator === null || validator === void 0 ? void 0 : validator.indicator) === 'error',
4292
+ "aria-required": required,
4250
4293
  autoComplete: autoComplete,
4251
- className: inputClassName,
4294
+ className: inputClassName || undefined,
4252
4295
  id: uuid,
4253
- onChange: localOnChange,
4296
+ onChange: handleChange,
4254
4297
  role: role,
4255
4298
  rows: rows,
4256
4299
  value: localValue,
4257
4300
  "data-testid": dataTestId,
4258
- maxLength: maxLength
4301
+ maxLength: maxLength,
4302
+ required: required
4259
4303
  }, props))
4260
4304
  }))
4261
4305
  }));
@@ -4402,7 +4446,7 @@ const Link = _a => {
4402
4446
  }));
4403
4447
  };
4404
4448
 
4405
- const ListItem = _a => {
4449
+ const ListItem$1 = _a => {
4406
4450
  var {
4407
4451
  listType,
4408
4452
  tableRowData,
@@ -4436,7 +4480,7 @@ const List$1 = _a => {
4436
4480
  props = __rest(_a, ["listType", "tableCaption", "tableData", "children"]);
4437
4481
  if (listType === 'ordered') {
4438
4482
  return jsx("ol", Object.assign({}, props, {
4439
- children: children === null || children === void 0 ? void 0 : children.map((child, index) => jsx(ListItem, {
4483
+ children: children === null || children === void 0 ? void 0 : children.map((child, index) => jsx(ListItem$1, {
4440
4484
  children: child
4441
4485
  }, index))
4442
4486
  }));
@@ -4444,7 +4488,7 @@ const List$1 = _a => {
4444
4488
  return jsx("ul", Object.assign({}, props, {
4445
4489
  className: listType
4446
4490
  }, {
4447
- children: children === null || children === void 0 ? void 0 : children.map((child, index) => jsx(ListItem, {
4491
+ children: children === null || children === void 0 ? void 0 : children.map((child, index) => jsx(ListItem$1, {
4448
4492
  children: child
4449
4493
  }, index))
4450
4494
  }));
@@ -4455,7 +4499,7 @@ const List$1 = _a => {
4455
4499
  }, {
4456
4500
  children: tableCaption
4457
4501
  })), jsx("dl", {
4458
- children: tableData === null || tableData === void 0 ? void 0 : tableData.map((data, index) => jsx(ListItem, {
4502
+ children: tableData === null || tableData === void 0 ? void 0 : tableData.map((data, index) => jsx(ListItem$1, {
4459
4503
  listType: listType,
4460
4504
  tableRowData: data
4461
4505
  }, index))
@@ -4504,6 +4548,18 @@ var valueList$1 = /*#__PURE__*/Object.freeze({
4504
4548
  'default': valueList
4505
4549
  });
4506
4550
 
4551
+ registerTransitionalStyles();
4552
+ const GroupedList = createComponent({
4553
+ tagName: getScopedTagName('gds-grouped-list'),
4554
+ elementClass: GdsGroupedList,
4555
+ react: React
4556
+ });
4557
+ const ListItem = createComponent({
4558
+ tagName: getScopedTagName('gds-list-item'),
4559
+ elementClass: GdsGroupedList,
4560
+ react: React
4561
+ });
4562
+
4507
4563
  //TODO: Add variants
4508
4564
  const Navbar = ({
4509
4565
  children,
@@ -4563,75 +4619,56 @@ const Navbar = ({
4563
4619
  }));
4564
4620
  };
4565
4621
 
4566
- const Select = /*#__PURE__*/React.forwardRef(({
4567
- id,
4568
- className,
4569
- children,
4570
- validator,
4571
- label,
4572
- labelInformation,
4573
- defaultValue,
4574
- value,
4575
- testId,
4576
- onChange,
4577
- onSelect,
4578
- expandableInfo,
4579
- expandableInfoButtonLabel,
4580
- name
4581
- }, ref) => {
4582
- const selectId = id !== null && id !== void 0 ? id : randomId();
4583
- const validatorClassName = validateClassName(validator === null || validator === void 0 ? void 0 : validator.indicator);
4622
+ const Select = /*#__PURE__*/React.forwardRef((_a, ref) => {
4623
+ var {
4624
+ 'aria-describedby': ariaDescribedBy,
4625
+ id = randomId(),
4626
+ validator,
4627
+ label,
4628
+ info,
4629
+ testId,
4630
+ expandableInfo,
4631
+ expandableInfoButtonLabel,
4632
+ required
4633
+ } = _a,
4634
+ props = __rest(_a, ['aria-describedby', "id", "validator", "label", "info", "testId", "expandableInfo", "expandableInfoButtonLabel", "required"]);
4635
+ const [uuid] = useState(id);
4636
+ const selectClassName = classNames('gds-select', {
4637
+ [`${validateClassName(validator === null || validator === void 0 ? void 0 : validator.indicator)}`]: validator
4638
+ });
4639
+ const describedBy = classNames(ariaDescribedBy, {
4640
+ [`${uuid}_info`]: info,
4641
+ [`gds-expandable-info-${uuid}`]: expandableInfo,
4642
+ [`${uuid}_message`]: (validator === null || validator === void 0 ? void 0 : validator.message) !== undefined && validator.message.length > 0
4643
+ });
4584
4644
  return jsx(FormItem, Object.assign({
4585
4645
  label: label,
4586
- labelInformation: labelInformation,
4646
+ labelInformation: info !== null && info !== void 0 ? info : props.labelInformation,
4587
4647
  expandableInfo: expandableInfo,
4588
4648
  expandableInfoButtonLabel: expandableInfoButtonLabel,
4589
- inputId: selectId,
4649
+ inputId: uuid,
4590
4650
  validator: validator
4591
4651
  }, {
4592
4652
  children: jsxs("div", Object.assign({
4593
- className: `gds-select ${validatorClassName}`
4653
+ className: selectClassName
4594
4654
  }, {
4595
4655
  children: [jsx("select", Object.assign({
4596
- id: selectId,
4656
+ "aria-describedby": describedBy || undefined,
4657
+ "aria-invalid": (validator === null || validator === void 0 ? void 0 : validator.indicator) === 'error',
4658
+ "aria-required": required,
4659
+ id: uuid,
4597
4660
  "data-testid": testId,
4598
- className: className,
4599
- name: name,
4600
- defaultValue: defaultValue,
4601
- value: value,
4602
4661
  ref: ref,
4603
- onChange: event => {
4604
- onChange && onChange(event);
4605
- }
4606
- }, {
4607
- children: children
4608
- })), jsx(ChevronDown, {})]
4662
+ required: required
4663
+ }, props)), jsx(ChevronDown, {})]
4609
4664
  }))
4610
4665
  }));
4611
4666
  });
4612
- const Option = _a => {
4613
- var {
4614
- value,
4615
- children
4616
- } = _a,
4617
- rest = __rest(_a, ["value", "children"]);
4618
- return jsx("option", Object.assign({
4619
- value: value
4620
- }, rest, {
4621
- children: children
4622
- }));
4667
+ const Option = props => {
4668
+ return jsx("option", Object.assign({}, props));
4623
4669
  };
4624
- const OptionGroup = ({
4625
- label,
4626
- disabled,
4627
- children
4628
- }) => {
4629
- return jsx("optgroup", Object.assign({
4630
- label: label,
4631
- disabled: disabled
4632
- }, {
4633
- children: children
4634
- }));
4670
+ const OptionGroup = props => {
4671
+ return jsx("optgroup", Object.assign({}, props));
4635
4672
  };
4636
4673
 
4637
4674
  var anObject$3 = anObject$e;
@@ -6469,4 +6506,4 @@ const Table = /*#__PURE__*/React.memo( /*#__PURE__*/React.forwardRef((_a, ref) =
6469
6506
  }));
6470
6507
  }));
6471
6508
 
6472
- export { Accordion, AlertRibbon as Alert, AlertRibbon, Badge, Button, ButtonGroup, Card, Checkbox, ContextMenu, CoreDatepicker, CoreDropdown, CoreMenuHeading, CoreOption, Datepicker, Dropdown, EmailInput, Flexbox, Form, FormItem, FormItems, Group, IconButton, InPageWizardStepCard, Input, Link, List$1 as List, MenuItem, Modal, Navbar, NumberInput, Option, OptionGroup, RadioButton, RadioGroup, Select, Slider, SortDirection, Stepper, Tab, Table, TableBody, TableCell, TableContext, TableHeader, TableHeaderCell, TableRow, Tabs, Text, TextArea, TextInput, valueList$1 as ValueList, filterArrayByColumns, onRowSelect, paginate, searchTextByColumns, sortArray, sumCols, useTableContext };
6509
+ export { Accordion, AlertRibbon as Alert, AlertRibbon, Badge, Button, ButtonGroup, Card, Checkbox, ContextMenu, CoreDatepicker, CoreDropdown, CoreMenuHeading, CoreOption, Datepicker, Dropdown, EmailInput, Flexbox, Form, FormItem, FormItems, Group, GroupedList, IconButton, InPageWizardStepCard, Input, Link, List$1 as List, ListItem, MenuItem, Modal, Navbar, NumberInput, Option, OptionGroup, RadioButton, RadioGroup, Select, Slider, SortDirection, Stepper, Tab, Table, TableBody, TableCell, TableContext, TableHeader, TableHeaderCell, TableRow, Tabs, Text, TextArea, TextInput, valueList$1 as ValueList, filterArrayByColumns, onRowSelect, paginate, searchTextByColumns, sortArray, sumCols, useTableContext };
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "@sebgroup/green-react",
3
- "version": "3.2.0",
3
+ "version": "3.4.0",
4
4
  "peerDependencies": {
5
5
  "react": "^17 || ^18",
6
6
  "react-dom": "^17 || ^18"
7
7
  },
8
8
  "dependencies": {
9
- "@sebgroup/green-core": "^1.6.0",
10
- "@sebgroup/chlorophyll": "^3.0.5",
11
- "@sebgroup/extract": "^3.0.0",
9
+ "@sebgroup/green-core": "^1.8.0",
10
+ "@sebgroup/chlorophyll": "^3.1.1",
11
+ "@sebgroup/extract": "^3.0.1",
12
12
  "@lit/react": "^1.0.2",
13
13
  "classnames": "^2.3.2"
14
14
  },
package/src/index.d.ts CHANGED
@@ -10,6 +10,7 @@ export * from './lib/layout';
10
10
  export * from './lib/in-page-wizard';
11
11
  export * from './lib/link/link';
12
12
  export * from './lib/list';
13
+ export * from './lib/grouped-list/grouped-list';
13
14
  export * from './lib/navbar/navbar';
14
15
  export * from './lib/select';
15
16
  export * from './lib/slider';
@@ -10,6 +10,8 @@ export interface DatepickerOptions {
10
10
  value?: Date;
11
11
  showWeeks?: boolean;
12
12
  testId?: string;
13
+ size?: 'small' | 'medium';
14
+ hideLabel?: boolean;
13
15
  /** @deprecated Use `value` instead */
14
16
  selectedDate?: Date;
15
17
  /** @deprecated Use `value` instead */
@@ -30,6 +30,10 @@ export interface DropdownArgs {
30
30
  value?: any;
31
31
  /** Force width of the popover to match trigger */
32
32
  syncPopoverWidth?: boolean;
33
+ /** Size of the dropdown trigger */
34
+ size?: 'small' | 'medium';
35
+ /** Hide the label */
36
+ hideLabel?: boolean;
33
37
  }
34
38
  export interface DropdownTexts {
35
39
  placeholder?: string;
@@ -48,5 +52,5 @@ export declare const CoreOption: import("@lit/react").ReactWebComponent<GdsOptio
48
52
  export interface DropdownProps extends DropdownArgs {
49
53
  onChange?: OnChange;
50
54
  }
51
- export declare const Dropdown: ({ compareWith, display, id, informationLabel, label, multiSelect, onChange, options, searchFilter, searchable, texts, useValue, validator, value, syncPopoverWidth, }: DropdownProps) => import("react/jsx-runtime").JSX.Element;
55
+ export declare const Dropdown: ({ compareWith, display, id, informationLabel, label, multiSelect, onChange, options, searchFilter, searchable, texts, useValue, validator, value, syncPopoverWidth, ...props }: DropdownProps) => import("react/jsx-runtime").JSX.Element;
52
56
  export default Dropdown;
@@ -12,4 +12,4 @@ export interface CheckboxProps extends HTMLProps<HTMLInputElement> {
12
12
  /** A handler function that takes the event and can act on it */
13
13
  onChange?: FormEventHandler<HTMLInputElement>;
14
14
  }
15
- export declare const Checkbox: ({ label, onChange, validator, testId, ...props }: CheckboxProps) => import("react/jsx-runtime").JSX.Element;
15
+ export declare const Checkbox: ({ "aria-describedby": ariaDescribedBy, id, label, validator, testId, required, className, ...props }: CheckboxProps) => import("react/jsx-runtime").JSX.Element;
@@ -18,7 +18,7 @@ export interface InputProps extends IExpandableInformation, DetailedHTMLProps<In
18
18
  /** Function called when input value changes */
19
19
  onChangeInput?: (value: string) => string;
20
20
  }
21
- export declare const Input: ({ "aria-describedby": ariaDescribedBy, autoComplete, children, className, testId: dataTestId, expandableInfo, expandableInfoButtonLabel, formatter, id, label, info, onChange, unit, role, validator, onChangeInput, value, ...props }: InputProps) => import("react/jsx-runtime").JSX.Element;
21
+ export declare const Input: ({ "aria-describedby": ariaDescribedBy, autoComplete, children, className, testId: dataTestId, expandableInfo, expandableInfoButtonLabel, formatter, id, label, info, onChange, unit, role, validator, onChangeInput, value, required, ...props }: InputProps) => import("react/jsx-runtime").JSX.Element;
22
22
  export declare const TextInput: (props: Omit<InputProps, 'type'>) => import("react/jsx-runtime").JSX.Element;
23
23
  export declare const EmailInput: (props: Omit<InputProps, 'type'>) => import("react/jsx-runtime").JSX.Element;
24
24
  export declare const NumberInput: (props: Omit<InputProps, 'type'>) => import("react/jsx-runtime").JSX.Element;
@@ -12,4 +12,4 @@ export interface ITextAreaProps extends IExpandableInformation, DetailedHTMLProp
12
12
  /** Value of textarea */
13
13
  value?: string;
14
14
  }
15
- export declare const TextArea: ({ "aria-describedby": ariaDescribedBy, autoComplete, className, expandableInfo, expandableInfoButtonLabel, id, label, info, onChange, role, rows, validator, value, testId: dataTestId, maxLength, ...props }: ITextAreaProps) => import("react/jsx-runtime").JSX.Element;
15
+ export declare const TextArea: ({ "aria-describedby": ariaDescribedBy, autoComplete, className, expandableInfo, expandableInfoButtonLabel, id, label, info, onChange, role, rows, validator, value, testId: dataTestId, maxLength, required, ...props }: ITextAreaProps) => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,3 @@
1
+ import { GdsGroupedList } from '@sebgroup/green-core';
2
+ export declare const GroupedList: import("@lit/react").ReactWebComponent<GdsGroupedList, {}>;
3
+ export declare const ListItem: import("@lit/react").ReactWebComponent<GdsGroupedList, {}>;
@@ -1,42 +1,25 @@
1
- import React, { ReactNode } from 'react';
2
- import { IValidator } from '@sebgroup/extract';
3
- import { SelectorAttributesProps, LabelProps } from '../../types';
4
- export interface SelectProps extends SelectorAttributesProps, LabelProps {
5
- children: ReactNode;
6
- validator?: IValidator;
7
- onChange?: (event: React.ChangeEvent<HTMLSelectElement>) => void;
8
- onSelect?: (event: React.ChangeEvent<HTMLSelectElement>) => void;
9
- defaultValue?: string | number;
10
- value?: string | number;
11
- testId?: string;
12
- expandableInfo?: string;
13
- expandableInfoButtonLabel?: string;
14
- name?: string;
15
- }
16
- interface OptionProps {
17
- children: string;
18
- value: string | number;
19
- disabled?: boolean;
20
- invalid?: boolean;
21
- autocomplete?: string;
22
- autofocus?: boolean;
23
- form?: string;
24
- name?: string;
25
- required?: boolean;
26
- size?: number;
27
- selected?: boolean;
28
- }
29
- interface OptionGroupProps {
1
+ import React from 'react';
2
+ import { IExpandableInformation, ILabelAndLabelInformation, IValidator } from '@sebgroup/extract';
3
+ export interface SelectProps extends IExpandableInformation, ILabelAndLabelInformation, React.DetailedHTMLProps<React.SelectHTMLAttributes<HTMLSelectElement>, HTMLSelectElement> {
30
4
  label: string;
31
- children: React.ReactElement<OptionProps> | React.ReactElement<OptionProps>[];
32
- disabled?: boolean;
5
+ info?: string;
6
+ validator?: IValidator | undefined;
7
+ value?: string;
8
+ testId?: string;
9
+ /**
10
+ * @deprecated
11
+ * Use `info` instead
12
+ */
13
+ labelInformation?: string;
33
14
  }
34
- export declare const Select: React.ForwardRefExoticComponent<SelectProps & React.RefAttributes<HTMLSelectElement>>;
35
- export declare const Option: ({ value, children, ...rest }: OptionProps) => import("react/jsx-runtime").JSX.Element;
36
- export declare const OptionGroup: ({ label, disabled, children, }: OptionGroupProps) => import("react/jsx-runtime").JSX.Element;
15
+ export declare const Select: React.ForwardRefExoticComponent<Omit<SelectProps, "ref"> & React.RefAttributes<HTMLSelectElement>>;
16
+ declare type OptionProps = React.DetailedHTMLProps<React.OptionHTMLAttributes<HTMLOptionElement>, HTMLOptionElement>;
17
+ export declare const Option: (props: OptionProps) => import("react/jsx-runtime").JSX.Element;
18
+ declare type OptGroupProps = React.DetailedHTMLProps<React.OptgroupHTMLAttributes<HTMLOptGroupElement>, HTMLOptGroupElement>;
19
+ export declare const OptionGroup: (props: OptGroupProps) => import("react/jsx-runtime").JSX.Element;
37
20
  declare const _default: {
38
- Select: React.ForwardRefExoticComponent<SelectProps & React.RefAttributes<HTMLSelectElement>>;
39
- Option: ({ value, children, ...rest }: OptionProps) => import("react/jsx-runtime").JSX.Element;
40
- OptionGroup: ({ label, disabled, children, }: OptionGroupProps) => import("react/jsx-runtime").JSX.Element;
21
+ Select: React.ForwardRefExoticComponent<Omit<SelectProps, "ref"> & React.RefAttributes<HTMLSelectElement>>;
22
+ Option: (props: OptionProps) => import("react/jsx-runtime").JSX.Element;
23
+ OptionGroup: (props: OptGroupProps) => import("react/jsx-runtime").JSX.Element;
41
24
  };
42
25
  export default _default;