@festo-ui/react 7.3.0-dev.465 → 7.3.0-dev.469

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.
Files changed (51) hide show
  1. package/index.css +1 -1
  2. package/lib/components/icons/close-small.d.ts +7 -0
  3. package/lib/components/icons/close-small.js +70 -0
  4. package/lib/forms/checkbox/Checkbox.d.ts +1 -1
  5. package/lib/forms/select/Select.d.ts +15 -9
  6. package/lib/forms/select/Select.js +68 -253
  7. package/lib/forms/select/internal/HiddenInput.d.ts +9 -0
  8. package/lib/forms/select/internal/HiddenInput.js +26 -0
  9. package/lib/forms/select/internal/ListItem.d.ts +18 -0
  10. package/lib/forms/select/internal/ListItem.js +84 -0
  11. package/lib/forms/select/internal/SelectButton.d.ts +13 -0
  12. package/lib/forms/select/internal/SelectButton.js +57 -0
  13. package/lib/forms/select/internal/SelectButtonContent.d.ts +8 -0
  14. package/lib/forms/select/internal/SelectButtonContent.js +39 -0
  15. package/lib/forms/select/internal/SelectCheckbox.d.ts +5 -0
  16. package/lib/forms/select/internal/SelectCheckbox.js +20 -0
  17. package/lib/forms/select/internal/SelectLabel.d.ts +8 -0
  18. package/lib/forms/select/internal/SelectLabel.js +16 -0
  19. package/lib/forms/select/internal/SelectOptionsContainer.d.ts +17 -0
  20. package/lib/forms/select/internal/SelectOptionsContainer.js +104 -0
  21. package/lib/forms/select/internal/SelectScrollContainer.d.ts +9 -0
  22. package/lib/forms/select/internal/SelectScrollContainer.js +22 -0
  23. package/lib/forms/select/internal/SelectWrapper.d.ts +6 -0
  24. package/lib/forms/select/internal/SelectWrapper.js +20 -0
  25. package/lib/forms/select/internal/index.d.ts +6 -0
  26. package/lib/forms/select/internal/index.js +6 -0
  27. package/lib/forms/select/internal/utils.d.ts +7 -0
  28. package/lib/forms/select/internal/utils.js +36 -0
  29. package/lib/forms/select/select-option/SelectOption.d.ts +10 -6
  30. package/lib/forms/select/select-option/SelectOption.js +3 -2
  31. package/lib/helper/useControlled.d.ts +3 -2
  32. package/lib/helper/useControlled.js +6 -2
  33. package/node/lib/components/icons/close-small.js +75 -0
  34. package/node/lib/forms/select/Select.js +69 -255
  35. package/node/lib/forms/select/internal/HiddenInput.js +32 -0
  36. package/node/lib/forms/select/internal/ListItem.js +93 -0
  37. package/node/lib/forms/select/internal/SelectButton.js +64 -0
  38. package/node/lib/forms/select/internal/SelectButtonContent.js +45 -0
  39. package/node/lib/forms/select/internal/SelectCheckbox.js +26 -0
  40. package/node/lib/forms/select/internal/SelectLabel.js +23 -0
  41. package/node/lib/forms/select/internal/SelectOptionsContainer.js +109 -0
  42. package/node/lib/forms/select/internal/SelectScrollContainer.js +28 -0
  43. package/node/lib/forms/select/internal/SelectWrapper.js +27 -0
  44. package/node/lib/forms/select/internal/index.js +48 -0
  45. package/node/lib/forms/select/internal/utils.js +43 -0
  46. package/node/lib/forms/select/select-option/SelectOption.js +4 -3
  47. package/node/lib/helper/useControlled.js +6 -2
  48. package/package.json +1 -1
  49. package/lib/forms/select/list-item/ListItem.d.ts +0 -6
  50. package/lib/forms/select/list-item/ListItem.js +0 -24
  51. package/node/lib/forms/select/list-item/ListItem.js +0 -33
@@ -0,0 +1,17 @@
1
+ import { Key, Ref } from 'react';
2
+ import { SelectConfiguration } from '../../../helper/types';
3
+ import { SelectOptionType } from '../select-option/SelectOption';
4
+ interface SelectOptionsContainerProps<T> {
5
+ options?: SelectOptionType<T>[];
6
+ config?: SelectConfiguration;
7
+ onClose: () => void;
8
+ label?: string | string[];
9
+ onOptionChange: (option: SelectOptionType<T>) => void;
10
+ multiple?: boolean;
11
+ children: React.ReactNode;
12
+ }
13
+ declare function SelectOptionsContainerComponent<T extends Key | null | undefined>({ options, config, onClose, label, onOptionChange, multiple, children, }: SelectOptionsContainerProps<T>, ref: Ref<HTMLDivElement>): JSX.Element;
14
+ declare const SelectOptionsContainer: <T>(props: SelectOptionsContainerProps<T> & {
15
+ ref?: Ref<HTMLDivElement> | undefined;
16
+ }) => ReturnType<typeof SelectOptionsContainerComponent>;
17
+ export default SelectOptionsContainer;
@@ -0,0 +1,104 @@
1
+ import { createRef, forwardRef, isValidElement, useEffect, useRef, useState } from 'react';
2
+ import { usePopper } from 'react-popper';
3
+ import SelectScrollContainer from "./SelectScrollContainer.js";
4
+ import ListItem from "./ListItem.js";
5
+ import getChildren from "./utils.js";
6
+ import { jsx as _jsx } from "react/jsx-runtime";
7
+ import { jsxs as _jsxs } from "react/jsx-runtime";
8
+ import { Fragment as _Fragment } from "react/jsx-runtime";
9
+ function SelectOptionsContainerComponent(_ref, ref) {
10
+ let {
11
+ options,
12
+ config,
13
+ onClose,
14
+ label,
15
+ onOptionChange,
16
+ multiple,
17
+ children
18
+ } = _ref;
19
+ const [popperElement, setPopperElement] = useState(null);
20
+ const refObject = typeof ref !== 'function' ? ref?.current : null;
21
+ const {
22
+ styles,
23
+ attributes
24
+ } = usePopper(refObject, popperElement, {
25
+ placement: 'bottom-start',
26
+ modifiers: [{
27
+ name: 'offset',
28
+ options: {
29
+ offset: [0, 3]
30
+ }
31
+ }, {
32
+ name: 'flip',
33
+ options: {
34
+ fallbackPlacements: ['bottom-start', 'top-start']
35
+ }
36
+ }]
37
+ });
38
+ function getCssProperies() {
39
+ if (config?.contentWidth) {
40
+ return {
41
+ ...styles.popper,
42
+ minWidth: `${refObject?.clientWidth}px`,
43
+ width: config?.contentWidth
44
+ };
45
+ }
46
+ return {
47
+ ...styles.popper,
48
+ minWidth: `${refObject?.clientWidth}px`
49
+ };
50
+ }
51
+ const allChildren = getChildren(children);
52
+ const childrenList = allChildren.childrenList;
53
+ const usedOptions = options ?? childrenList.map(child => child.props.option);
54
+ const {
55
+ length
56
+ } = usedOptions;
57
+ const listItemRef = useRef(Array.from({
58
+ length
59
+ }, () => /*#__PURE__*/createRef()));
60
+ const selectedIndex = Array.isArray(label) ? usedOptions.findIndex(option => option.label === label.at(-1)) : usedOptions.findIndex(option => option.label === label);
61
+ const [init, setInit] = useState(false);
62
+ useEffect(() => {
63
+ if (!init) {
64
+ requestAnimationFrame(() => {
65
+ setInit(true);
66
+ const index = selectedIndex === -1 ? 0 : selectedIndex;
67
+ listItemRef.current?.[index].current?.focus();
68
+ });
69
+ }
70
+ }, [selectedIndex, init]);
71
+ const onCloseRef = useRef(onClose);
72
+ useEffect(() => () => {
73
+ onCloseRef.current();
74
+ }, []);
75
+ return /*#__PURE__*/_jsxs(_Fragment, {
76
+ children: [/*#__PURE__*/_jsx("div", {
77
+ "aria-hidden": true,
78
+ className: "fr-backdrop",
79
+ onClick: onClose
80
+ }), /*#__PURE__*/_jsxs("ul", {
81
+ ref: setPopperElement,
82
+ style: getCssProperies(),
83
+ ...attributes.popper,
84
+ className: "fwe-select-options-container",
85
+ children: [allChildren.before, /*#__PURE__*/_jsx(SelectScrollContainer, {
86
+ length: length,
87
+ config: config,
88
+ children: [...(options || []), ...childrenList].map((item, i) => /*#__PURE__*/_jsx(ListItem, {
89
+ withCheckbox: multiple,
90
+ item: item,
91
+ selectedLabel: label,
92
+ onClose: onClose,
93
+ onFocusChange: index => listItemRef.current[index].current?.focus(),
94
+ onOptionChange: onOptionChange,
95
+ ref: listItemRef,
96
+ index: i,
97
+ options: usedOptions
98
+ }, ( /*#__PURE__*/isValidElement(item) ? item.props.option : item).data))
99
+ }), allChildren.after]
100
+ })]
101
+ });
102
+ }
103
+ const SelectOptionsContainer = /*#__PURE__*/forwardRef(SelectOptionsContainerComponent);
104
+ export default SelectOptionsContainer;
@@ -0,0 +1,9 @@
1
+ /// <reference types="react" />
2
+ import { SelectConfiguration } from '../../../helper/types';
3
+ interface SelectScrollContainerProps {
4
+ config?: SelectConfiguration;
5
+ children: React.ReactNode;
6
+ length: number;
7
+ }
8
+ export default function SelectScrollContainer({ config, children, length, }: SelectScrollContainerProps): JSX.Element;
9
+ export {};
@@ -0,0 +1,22 @@
1
+ import calcVirtualScrollHeight from "../utils.js";
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ import { Fragment as _Fragment } from "react/jsx-runtime";
4
+ export default function SelectScrollContainer(_ref) {
5
+ let {
6
+ config,
7
+ children,
8
+ length
9
+ } = _ref;
10
+ if (config?.scroll?.enabled) {
11
+ return /*#__PURE__*/_jsx("div", {
12
+ className: "fr-select-scroll",
13
+ style: {
14
+ height: calcVirtualScrollHeight(config, length)
15
+ },
16
+ children: children
17
+ });
18
+ }
19
+ return /*#__PURE__*/_jsx(_Fragment, {
20
+ children: children
21
+ });
22
+ }
@@ -0,0 +1,6 @@
1
+ import { ComponentPropsWithoutRef } from 'react';
2
+ interface SelectWrapperProps extends ComponentPropsWithoutRef<'div'> {
3
+ disabled?: boolean;
4
+ }
5
+ declare const SelectWrapper: (props: SelectWrapperProps & import("react").RefAttributes<HTMLDivElement>) => import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>> | null;
6
+ export default SelectWrapper;
@@ -0,0 +1,20 @@
1
+ import cn from 'classnames';
2
+ import { forwardRef } from 'react';
3
+ import { jsx as _jsx } from "react/jsx-runtime";
4
+ const SelectWrapper = /*#__PURE__*/forwardRef((_ref, ref) => {
5
+ let {
6
+ children,
7
+ disabled,
8
+ className,
9
+ ...props
10
+ } = _ref;
11
+ return /*#__PURE__*/_jsx("div", {
12
+ ...props,
13
+ ref: ref,
14
+ className: cn('fwe-select-wrapper', {
15
+ 'fwe-disabled': disabled
16
+ }, className),
17
+ children: children
18
+ });
19
+ });
20
+ export default SelectWrapper;
@@ -0,0 +1,6 @@
1
+ export { default as HiddenInput } from './HiddenInput';
2
+ export { default as ListItem } from './ListItem';
3
+ export { default as SelectButton } from './SelectButton';
4
+ export { default as OptionsContainer } from './SelectOptionsContainer';
5
+ export { default as Wrapper } from './SelectWrapper';
6
+ export { default as SelectLabel } from './SelectLabel';
@@ -0,0 +1,6 @@
1
+ export { default as HiddenInput } from "./HiddenInput.js";
2
+ export { default as ListItem } from "./ListItem.js";
3
+ export { default as SelectButton } from "./SelectButton.js";
4
+ export { default as OptionsContainer } from "./SelectOptionsContainer.js";
5
+ export { default as Wrapper } from "./SelectWrapper.js";
6
+ export { default as SelectLabel } from "./SelectLabel.js";
@@ -0,0 +1,7 @@
1
+ import React from 'react';
2
+ import { SelectOptionProps } from '../select-option/SelectOption';
3
+ export default function getChildren<T>(children: React.ReactNode): {
4
+ childrenList: React.ReactElement<SelectOptionProps<T>, string | React.JSXElementConstructor<any>>[];
5
+ after: React.ReactElement<any, string | React.JSXElementConstructor<any>>[];
6
+ before: React.ReactElement<any, string | React.JSXElementConstructor<any>>[];
7
+ };
@@ -0,0 +1,36 @@
1
+ import React from 'react';
2
+ import cn from 'classnames';
3
+ import SelectOption from "../select-option/SelectOption.js";
4
+ export default function getChildren(children) {
5
+ const before = [];
6
+ const childrenList = [];
7
+ const after = [];
8
+ let foundFirstOption = false;
9
+ React.Children.forEach(children, element => {
10
+ if ( /*#__PURE__*/React.isValidElement(element)) {
11
+ if ( /*#__PURE__*/React.isValidElement(element) && element.type === SelectOption) {
12
+ foundFirstOption = true;
13
+ const className = cn('fwe-select-option-content', element.props.className);
14
+ const {
15
+ props
16
+ } = element;
17
+ childrenList.push({
18
+ ...element,
19
+ props: {
20
+ ...props,
21
+ className
22
+ }
23
+ });
24
+ } else if (!foundFirstOption) {
25
+ before.push(element);
26
+ } else {
27
+ after.push(element);
28
+ }
29
+ }
30
+ });
31
+ return {
32
+ childrenList,
33
+ after,
34
+ before
35
+ };
36
+ }
@@ -1,10 +1,14 @@
1
- import React from 'react';
2
- export interface SelectOptionType {
1
+ import React, { Ref } from 'react';
2
+ export interface SelectOptionType<T> {
3
3
  label: string;
4
- data: any;
4
+ data: T;
5
+ disabled?: boolean;
5
6
  }
6
- export interface SelectOptionProps extends React.ComponentPropsWithoutRef<'span'> {
7
- option: SelectOptionType;
7
+ export interface SelectOptionProps<T> extends React.ComponentPropsWithoutRef<'span'> {
8
+ option: SelectOptionType<T>;
8
9
  }
9
- export declare const SelectOption: (props: SelectOptionProps & React.RefAttributes<HTMLDivElement>) => React.ReactElement<any, string | React.JSXElementConstructor<any>> | null;
10
+ declare function SelectOptionComponent<T>({ children, className, ...props }: SelectOptionProps<T>, ref: Ref<HTMLDivElement>): JSX.Element;
11
+ declare const SelectOption: <T>(props: SelectOptionProps<T> & {
12
+ ref?: React.Ref<HTMLDivElement> | undefined;
13
+ }) => ReturnType<typeof SelectOptionComponent>;
10
14
  export default SelectOption;
@@ -1,6 +1,6 @@
1
1
  import React, { forwardRef } from 'react';
2
2
  import { jsx as _jsx } from "react/jsx-runtime";
3
- export const SelectOption = /*#__PURE__*/forwardRef((_ref, ref) => {
3
+ function SelectOptionComponent(_ref, ref) {
4
4
  let {
5
5
  children,
6
6
  className,
@@ -12,5 +12,6 @@ export const SelectOption = /*#__PURE__*/forwardRef((_ref, ref) => {
12
12
  ...props,
13
13
  children: children
14
14
  });
15
- });
15
+ }
16
+ const SelectOption = /*#__PURE__*/forwardRef(SelectOptionComponent);
16
17
  export default SelectOption;
@@ -1,6 +1,7 @@
1
1
  import { Dispatch, SetStateAction } from 'react';
2
2
  export interface UseControlledProps<T> {
3
3
  controlled: T | undefined;
4
- default: T | undefined;
4
+ default: T;
5
+ onChange?: (value: T) => void;
5
6
  }
6
- export default function useControlled<T>({ controlled, default: defaultValue, }: UseControlledProps<T>): [T | undefined, Dispatch<SetStateAction<T | undefined>>];
7
+ export default function useControlled<T>({ controlled, default: defaultValue, onChange, }: UseControlledProps<T>): [T | undefined, Dispatch<SetStateAction<T>>];
@@ -2,7 +2,8 @@ import { useRef, useState, useCallback } from 'react';
2
2
  export default function useControlled(_ref) {
3
3
  let {
4
4
  controlled,
5
- default: defaultValue
5
+ default: defaultValue,
6
+ onChange
6
7
  } = _ref;
7
8
  const {
8
9
  current: isControlled
@@ -13,6 +14,9 @@ export default function useControlled(_ref) {
13
14
  if (!isControlled) {
14
15
  setValue(newValue);
15
16
  }
16
- }, [isControlled]);
17
+ const setter = newValue;
18
+ const onChangeValue = typeof newValue === 'function' ? setter(controlled) : newValue;
19
+ onChange?.(onChangeValue);
20
+ }, [controlled, isControlled, onChange]);
17
21
  return [value, setValueIfUncontrolled];
18
22
  }
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = IconCloseSmall;
7
+ var _jsxRuntime = require("react/jsx-runtime");
8
+ function IconCloseSmall(_ref) {
9
+ let {
10
+ className,
11
+ svgProps,
12
+ festoColor,
13
+ size = 16
14
+ } = _ref;
15
+ if (size < 24) {
16
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)("svg", {
17
+ xmlns: "http://www.w3.org/2000/svg",
18
+ "data-name": "content",
19
+ viewBox: "0 0 16 16",
20
+ width: size,
21
+ height: size,
22
+ ...svgProps,
23
+ className: `fwe-svg-icon${className ? ` ${className}` : ''}`,
24
+ "aria-label": "close-small",
25
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("path", {
26
+ fill: "none",
27
+ d: "M0 0h16v16H0z",
28
+ "data-name": "abb55ae8-ca55-470c-87c3-4b06738b4360"
29
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)("path", {
30
+ fill: festoColor ? '#0091dc' : 'currentColor',
31
+ d: "M10.24 5.05 8 7.3 5.75 5.05l-.7.71L7.29 8l-2.24 2.25.7.7L8 8.71l2.24 2.24.71-.7L8.7 8l2.25-2.24z",
32
+ "data-name": "b64b1ed2-b831-435c-9cee-b9964260209d"
33
+ })]
34
+ });
35
+ }
36
+ if (size < 32 || size === 48) {
37
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)("svg", {
38
+ xmlns: "http://www.w3.org/2000/svg",
39
+ "data-name": "content",
40
+ viewBox: "0 0 24 24",
41
+ width: size,
42
+ height: size,
43
+ ...svgProps,
44
+ className: `fwe-svg-icon${className ? ` ${className}` : ''}`,
45
+ "aria-label": "close-small",
46
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("path", {
47
+ fill: "none",
48
+ d: "M0 0h24v24H0z"
49
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)("path", {
50
+ fill: festoColor ? '#0091dc' : 'currentColor',
51
+ d: "M16.95 8.464 15.536 7.05 12 10.586 8.464 7.05 7.05 8.464 10.586 12 7.05 15.536l1.414 1.414L12 13.414l3.536 3.536 1.414-1.414L13.414 12z"
52
+ })]
53
+ });
54
+ }
55
+ if (size >= 32) {
56
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)("svg", {
57
+ xmlns: "http://www.w3.org/2000/svg",
58
+ "data-name": "content",
59
+ viewBox: "0 0 32 32",
60
+ width: size,
61
+ height: size,
62
+ ...svgProps,
63
+ className: `fwe-svg-icon${className ? ` ${className}` : ''}`,
64
+ "aria-label": "close-small",
65
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("path", {
66
+ fill: "none",
67
+ d: "M0 0h32v32H0z"
68
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)("path", {
69
+ fill: festoColor ? '#0091dc' : 'currentColor',
70
+ d: "M21.48 9.1 16 14.59 10.51 9.1 9.1 10.52 14.58 16 9.1 21.49l1.41 1.41L16 17.42l5.48 5.48 1.42-1.41L17.41 16l5.49-5.48z"
71
+ })]
72
+ });
73
+ }
74
+ return null;
75
+ }