@sebgroup/green-react 1.0.0-beta.14 → 1.0.0-beta.18

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/index.esm.js CHANGED
@@ -1757,9 +1757,7 @@ function Card({
1757
1757
  }, {
1758
1758
  children: [jsx("header", {
1759
1759
  children: header
1760
- }), jsx("p", {
1761
- children: children
1762
- }), jsx("footer", {
1760
+ }), children, jsx("footer", {
1763
1761
  children: footer
1764
1762
  })]
1765
1763
  }));
@@ -1976,6 +1974,7 @@ const FormItems = ({
1976
1974
  }, []);
1977
1975
 
1978
1976
  const onChange = event => {
1977
+ if (!event.target) return;
1979
1978
  const {
1980
1979
  value,
1981
1980
  name,
@@ -2314,6 +2313,7 @@ if (DESCRIPTORS && isCallable(NativeSymbol) && (!('description' in SymbolPrototy
2314
2313
  }
2315
2314
 
2316
2315
  const RadioGroup = ({
2316
+ defaultSelected,
2317
2317
  description,
2318
2318
  title,
2319
2319
  validator,
@@ -2336,6 +2336,7 @@ const RadioGroup = ({
2336
2336
  var _a;
2337
2337
 
2338
2338
  if (radioBtnRef && radioBtnRef.current) {
2339
+ if (defaultSelected) setChecked(defaultSelected);
2339
2340
  const form = (_a = radioBtnRef === null || radioBtnRef === void 0 ? void 0 : radioBtnRef.current) === null || _a === void 0 ? void 0 : _a.form;
2340
2341
 
2341
2342
  const resetListner = () => {
@@ -2555,7 +2556,9 @@ const useDropdown = ({
2555
2556
  useValue,
2556
2557
  display,
2557
2558
  togglerRef,
2558
- listboxRef
2559
+ listboxRef,
2560
+ onChange,
2561
+ validator
2559
2562
  }) => {
2560
2563
  const [handler, setHandler] = useState();
2561
2564
  const [dropdown, setDropdown] = useState();
@@ -2593,7 +2596,14 @@ const useDropdown = ({
2593
2596
  className: (_a = o.classes) === null || _a === void 0 ? void 0 : _a.join(' '),
2594
2597
  children: o[dropdown.display],
2595
2598
  selected: o.selected,
2596
- onClick: () => handler === null || handler === void 0 ? void 0 : handler.select(o)
2599
+ onClick: () => {
2600
+ handler === null || handler === void 0 ? void 0 : handler.select(o).then(() => {
2601
+ if (onChange) {
2602
+ const result = options.find(item => item.key === o.key);
2603
+ result && onChange(result);
2604
+ }
2605
+ });
2606
+ }
2597
2607
  });
2598
2608
  });
2599
2609
  setListItems(newListItems);
@@ -2605,7 +2615,14 @@ const useDropdown = ({
2605
2615
  inputProps: {
2606
2616
  defaultChecked: o.selected,
2607
2617
  type: 'checkbox',
2608
- onChange: () => handler === null || handler === void 0 ? void 0 : handler.select(o, false)
2618
+ onChange: () => {
2619
+ handler === null || handler === void 0 ? void 0 : handler.select(o, false).then(() => {
2620
+ if (onChange) {
2621
+ const result = options.find(item => item.key === o.key);
2622
+ result && onChange(result);
2623
+ }
2624
+ });
2625
+ }
2609
2626
  },
2610
2627
  spanProps: {
2611
2628
  children: o[dropdown.display]
@@ -2639,7 +2656,12 @@ const useDropdown = ({
2639
2656
  loop,
2640
2657
  multiSelect
2641
2658
  }); // eslint-disable-next-line react-hooks/exhaustive-deps
2642
- }, [id, texts, options, loop, multiSelect, selectValue, useValue, display]); // Create dropdown handler
2659
+ }, [id, texts, options, loop, multiSelect, selectValue, useValue, display]); // When validator changes
2660
+
2661
+ useEffect(() => {
2662
+ if (!dropdown) return;
2663
+ if (validator) handler === null || handler === void 0 ? void 0 : handler.validate(validator);
2664
+ }, [validator]); // Create dropdown handler
2643
2665
 
2644
2666
  useEffect(() => {
2645
2667
  if (!handler && togglerRef.current && listboxRef.current) {
@@ -2651,7 +2673,8 @@ const useDropdown = ({
2651
2673
  multiSelect,
2652
2674
  selectValue,
2653
2675
  useValue,
2654
- display
2676
+ display,
2677
+ validator
2655
2678
  }, togglerRef.current, listboxRef.current, listboxRef.current, dd => setDropdown(dd)));
2656
2679
  }
2657
2680
 
@@ -2674,7 +2697,9 @@ const Dropdown = ({
2674
2697
  selectValue,
2675
2698
  useValue,
2676
2699
  display,
2677
- texts
2700
+ texts,
2701
+ onChange,
2702
+ validator
2678
2703
  }) => {
2679
2704
  var _a;
2680
2705
 
@@ -2696,9 +2721,13 @@ const Dropdown = ({
2696
2721
  display,
2697
2722
  togglerRef,
2698
2723
  listboxRef,
2699
- texts
2724
+ texts,
2725
+ onChange,
2726
+ validator
2700
2727
  });
2701
- return jsxs("div", {
2728
+ return jsxs("div", Object.assign({
2729
+ className: "form-group"
2730
+ }, {
2702
2731
  children: [jsx("button", Object.assign({
2703
2732
  type: "button"
2704
2733
  }, togglerProps, {
@@ -2733,8 +2762,12 @@ const Dropdown = ({
2733
2762
  }, {
2734
2763
  children: listItems.map(liProps => jsx("li", Object.assign({}, liProps), liProps.id))
2735
2764
  }))]
2765
+ })), validator && jsx("span", Object.assign({
2766
+ className: "form-info"
2767
+ }, {
2768
+ children: validator === null || validator === void 0 ? void 0 : validator.message
2736
2769
  }))]
2737
- });
2770
+ }));
2738
2771
  };
2739
2772
 
2740
2773
  export { Alert, Badge, Button, ButtonGroup, Card, Checkbox, Dropdown, EmailInput, Flexbox, Form, FormItems, Group, Link, List, Modal, Navbar, NumberInput, RadioButton, RadioGroup, RenderInput, Text, TextInput };
package/index.umd.js CHANGED
@@ -1763,9 +1763,7 @@
1763
1763
  }, {
1764
1764
  children: [jsxRuntime.jsx("header", {
1765
1765
  children: header
1766
- }), jsxRuntime.jsx("p", {
1767
- children: children
1768
- }), jsxRuntime.jsx("footer", {
1766
+ }), children, jsxRuntime.jsx("footer", {
1769
1767
  children: footer
1770
1768
  })]
1771
1769
  }));
@@ -1982,6 +1980,7 @@
1982
1980
  }, []);
1983
1981
 
1984
1982
  const onChange = event => {
1983
+ if (!event.target) return;
1985
1984
  const {
1986
1985
  value,
1987
1986
  name,
@@ -2320,6 +2319,7 @@
2320
2319
  }
2321
2320
 
2322
2321
  const RadioGroup = ({
2322
+ defaultSelected,
2323
2323
  description,
2324
2324
  title,
2325
2325
  validator,
@@ -2342,6 +2342,7 @@
2342
2342
  var _a;
2343
2343
 
2344
2344
  if (radioBtnRef && radioBtnRef.current) {
2345
+ if (defaultSelected) setChecked(defaultSelected);
2345
2346
  const form = (_a = radioBtnRef === null || radioBtnRef === void 0 ? void 0 : radioBtnRef.current) === null || _a === void 0 ? void 0 : _a.form;
2346
2347
 
2347
2348
  const resetListner = () => {
@@ -2561,7 +2562,9 @@
2561
2562
  useValue,
2562
2563
  display,
2563
2564
  togglerRef,
2564
- listboxRef
2565
+ listboxRef,
2566
+ onChange,
2567
+ validator
2565
2568
  }) => {
2566
2569
  const [handler, setHandler] = React.useState();
2567
2570
  const [dropdown, setDropdown] = React.useState();
@@ -2599,7 +2602,14 @@
2599
2602
  className: (_a = o.classes) === null || _a === void 0 ? void 0 : _a.join(' '),
2600
2603
  children: o[dropdown.display],
2601
2604
  selected: o.selected,
2602
- onClick: () => handler === null || handler === void 0 ? void 0 : handler.select(o)
2605
+ onClick: () => {
2606
+ handler === null || handler === void 0 ? void 0 : handler.select(o).then(() => {
2607
+ if (onChange) {
2608
+ const result = options.find(item => item.key === o.key);
2609
+ result && onChange(result);
2610
+ }
2611
+ });
2612
+ }
2603
2613
  });
2604
2614
  });
2605
2615
  setListItems(newListItems);
@@ -2611,7 +2621,14 @@
2611
2621
  inputProps: {
2612
2622
  defaultChecked: o.selected,
2613
2623
  type: 'checkbox',
2614
- onChange: () => handler === null || handler === void 0 ? void 0 : handler.select(o, false)
2624
+ onChange: () => {
2625
+ handler === null || handler === void 0 ? void 0 : handler.select(o, false).then(() => {
2626
+ if (onChange) {
2627
+ const result = options.find(item => item.key === o.key);
2628
+ result && onChange(result);
2629
+ }
2630
+ });
2631
+ }
2615
2632
  },
2616
2633
  spanProps: {
2617
2634
  children: o[dropdown.display]
@@ -2645,7 +2662,12 @@
2645
2662
  loop,
2646
2663
  multiSelect
2647
2664
  }); // eslint-disable-next-line react-hooks/exhaustive-deps
2648
- }, [id, texts, options, loop, multiSelect, selectValue, useValue, display]); // Create dropdown handler
2665
+ }, [id, texts, options, loop, multiSelect, selectValue, useValue, display]); // When validator changes
2666
+
2667
+ React.useEffect(() => {
2668
+ if (!dropdown) return;
2669
+ if (validator) handler === null || handler === void 0 ? void 0 : handler.validate(validator);
2670
+ }, [validator]); // Create dropdown handler
2649
2671
 
2650
2672
  React.useEffect(() => {
2651
2673
  if (!handler && togglerRef.current && listboxRef.current) {
@@ -2657,7 +2679,8 @@
2657
2679
  multiSelect,
2658
2680
  selectValue,
2659
2681
  useValue,
2660
- display
2682
+ display,
2683
+ validator
2661
2684
  }, togglerRef.current, listboxRef.current, listboxRef.current, dd => setDropdown(dd)));
2662
2685
  }
2663
2686
 
@@ -2680,7 +2703,9 @@
2680
2703
  selectValue,
2681
2704
  useValue,
2682
2705
  display,
2683
- texts
2706
+ texts,
2707
+ onChange,
2708
+ validator
2684
2709
  }) => {
2685
2710
  var _a;
2686
2711
 
@@ -2702,9 +2727,13 @@
2702
2727
  display,
2703
2728
  togglerRef,
2704
2729
  listboxRef,
2705
- texts
2730
+ texts,
2731
+ onChange,
2732
+ validator
2706
2733
  });
2707
- return jsxRuntime.jsxs("div", {
2734
+ return jsxRuntime.jsxs("div", Object.assign({
2735
+ className: "form-group"
2736
+ }, {
2708
2737
  children: [jsxRuntime.jsx("button", Object.assign({
2709
2738
  type: "button"
2710
2739
  }, togglerProps, {
@@ -2739,8 +2768,12 @@
2739
2768
  }, {
2740
2769
  children: listItems.map(liProps => jsxRuntime.jsx("li", Object.assign({}, liProps), liProps.id))
2741
2770
  }))]
2771
+ })), validator && jsxRuntime.jsx("span", Object.assign({
2772
+ className: "form-info"
2773
+ }, {
2774
+ children: validator === null || validator === void 0 ? void 0 : validator.message
2742
2775
  }))]
2743
- });
2776
+ }));
2744
2777
  };
2745
2778
 
2746
2779
  exports.Alert = Alert;
@@ -1,4 +1,5 @@
1
1
  import { DropdownOption, DropdownTexts } from '@sebgroup/extract';
2
+ import { IValidator } from "@sebgroup/extract";
2
3
  export interface DropdownProps {
3
4
  id?: string;
4
5
  texts?: DropdownTexts;
@@ -8,6 +9,8 @@ export interface DropdownProps {
8
9
  selectValue?: string;
9
10
  loop?: boolean;
10
11
  multiSelect?: boolean;
12
+ onChange?: (o: DropdownOption) => void;
13
+ validator?: IValidator;
11
14
  }
12
- export declare const Dropdown: ({ id, options, loop, multiSelect, selectValue, useValue, display, texts, }: DropdownProps) => JSX.Element;
15
+ export declare const Dropdown: ({ id, options, loop, multiSelect, selectValue, useValue, display, texts, onChange, validator }: DropdownProps) => JSX.Element;
13
16
  export default Dropdown;
@@ -1,5 +1,6 @@
1
1
  import { DropdownHandler, DropdownOption, DropdownTexts } from '@sebgroup/extract';
2
2
  import { HTMLAttributes, InputHTMLAttributes, RefObject } from 'react';
3
+ import { IValidator } from "@sebgroup/extract";
3
4
  interface HookArgs {
4
5
  id?: string;
5
6
  texts?: DropdownTexts;
@@ -11,6 +12,8 @@ interface HookArgs {
11
12
  display?: string;
12
13
  togglerRef: RefObject<HTMLElement>;
13
14
  listboxRef: RefObject<HTMLElement>;
15
+ onChange?: (o: DropdownOption) => void;
16
+ validator?: IValidator;
14
17
  }
15
18
  declare type Props = HTMLAttributes<HTMLElement>;
16
19
  interface CheckboxItem {
@@ -30,5 +33,5 @@ interface HookResult {
30
33
  listItems: Props[];
31
34
  multiSelectProps: MultiSelectProps;
32
35
  }
33
- export declare const useDropdown: ({ id, texts, options, loop, multiSelect, selectValue, useValue, display, togglerRef, listboxRef, }: HookArgs) => HookResult;
36
+ export declare const useDropdown: ({ id, texts, options, loop, multiSelect, selectValue, useValue, display, togglerRef, listboxRef, onChange, validator }: HookArgs) => HookResult;
34
37
  export {};
@@ -1,5 +1,5 @@
1
+ import { IValidator } from '@sebgroup/extract';
1
2
  import React from 'react';
2
- import { IValidator } from './types';
3
3
  export interface FormItemsProps {
4
4
  children: React.ReactNode;
5
5
  validate?: IValidator;
@@ -1,5 +1,6 @@
1
1
  import { InputHTMLAttributes } from 'react';
2
- import { CheckboxProps, IValidator, NumberInputProps, RadioButtonProps, TextInputProps } from '../types';
2
+ import { CheckboxProps, NumberInputProps, RadioButtonProps, TextInputProps } from '../types';
3
+ import { IValidator } from '@sebgroup/extract';
3
4
  import React from 'react';
4
5
  export declare type Renderer = (type: string, props: InputHTMLAttributes<HTMLInputElement>, onChange?: (event: React.ChangeEvent<HTMLInputElement>) => void, onChangeInput?: (value: string) => string, label?: string, info?: string, validator?: IValidator) => JSX.Element;
5
6
  export declare const RenderInput: Renderer;
@@ -1,12 +1,13 @@
1
1
  import React from 'react';
2
- import { IValidator } from '../types';
2
+ import { IValidator } from '@sebgroup/extract';
3
3
  export interface RadioGroupProps {
4
4
  title?: string;
5
+ defaultSelected?: string;
5
6
  description?: string;
6
7
  validator?: IValidator;
7
8
  onChangeRadio?: (value: string) => string;
8
9
  onChange?: (e: React.ChangeEvent<HTMLInputElement>) => void;
9
10
  name?: string;
10
11
  }
11
- export declare const RadioGroup: ({ description, title, validator, onChangeRadio, onChange, name, children }: React.PropsWithChildren<RadioGroupProps>) => JSX.Element;
12
+ export declare const RadioGroup: ({ defaultSelected, description, title, validator, onChangeRadio, onChange, name, children }: React.PropsWithChildren<RadioGroupProps>) => JSX.Element;
12
13
  export default RadioGroup;
@@ -1,4 +1,4 @@
1
- import { IndicatorType, ValidatorRules } from '@sebgroup/extract';
1
+ import { IValidator } from '@sebgroup/extract';
2
2
  import { HTMLProps } from 'react';
3
3
  export interface TextInputProps extends HTMLProps<HTMLInputElement> {
4
4
  type?: 'text' | 'email' | 'number';
@@ -21,8 +21,3 @@ export interface RadioButtonProps extends HTMLProps<HTMLInputElement> {
21
21
  value: string;
22
22
  }
23
23
  export declare type InputListener<T> = (newValue?: T) => unknown;
24
- export interface IValidator {
25
- message: string;
26
- indicator: IndicatorType;
27
- rules?: ValidatorRules;
28
- }
@@ -0,0 +1,3 @@
1
+ import { AbstractStepper, StepperArgs, StepperData } from '@sebgroup/extract';
2
+ export { StepperArgs };
3
+ export declare const useStepper: ({ min, max, value, step, id }: StepperArgs) => [AbstractStepper, StepperData];
@@ -0,0 +1,8 @@
1
+ import { StepperArgs } from './hook';
2
+ export interface StepperProps extends StepperArgs {
3
+ label?: string;
4
+ description?: string;
5
+ statusMessage?: string;
6
+ onChange?: (value: number) => void;
7
+ }
8
+ export declare function Stepper({ label, description, statusMessage, onChange, ...props }: StepperProps): JSX.Element;
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@sebgroup/green-react",
3
- "version": "1.0.0-beta.14",
3
+ "version": "1.0.0-beta.18",
4
4
  "peerDependencies": {
5
5
  "react": "^17 || ^18",
6
6
  "react-dom": "^17 || ^18"
7
7
  },
8
8
  "dependencies": {
9
- "@sebgroup/chlorophyll": "^1.0.0-beta.14",
10
- "@sebgroup/extract": "^1.0.0-beta.14"
9
+ "@sebgroup/chlorophyll": "^1.0.0-beta.17",
10
+ "@sebgroup/extract": "^1.0.0-beta.17"
11
11
  },
12
12
  "description": "React components built on top of @sebgroup/chlorophyll.",
13
13
  "repository": {