@homecode/ui 4.26.10 → 4.27.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/dist/esm/index.js CHANGED
@@ -46,6 +46,7 @@ export { default as VirtualizedList } from './src/components/Virtualized/List/Li
46
46
  export { default as VirtualizedListScroll } from './src/components/Virtualized/List/ListScroll.js';
47
47
  import * as Virtualized_types from './src/components/Virtualized/Virtualized.types.js';
48
48
  export { Virtualized_types as VirtualizedTypes };
49
+ export { Toggle } from './src/components/Toggle/Toggle.js';
49
50
  import * as i18n from './src/services/i18n.js';
50
51
  export { i18n };
51
52
  import * as env from './src/tools/env.js';
@@ -83,6 +84,7 @@ import 'react';
83
84
  export { useIsMounted } from './src/hooks/useIsMounted.js';
84
85
  export { useListKeyboardControl } from './src/hooks/useListKeyboardControl.js';
85
86
  export { useResizeObserver } from './src/hooks/useResizeObserver.js';
87
+ export { useToggleState } from './src/hooks/useToggleState.js';
86
88
  import * as Form_types from './src/components/Form/Form.types.js';
87
89
  export { Form_types as FormTypes };
88
90
  export { SubmitButtons } from './src/components/Form/SubmitButtons/SubmitButtons.js';
@@ -59,6 +59,7 @@ import '../Text/Text.js';
59
59
  import '../Virtualized/Virtualized.styl.js';
60
60
  import '../Virtualized/List/List.styl.js';
61
61
  import '../Virtualized/List/ListScroll.styl.js';
62
+ import '../Toggle/Toggle.styl.js';
62
63
 
63
64
  function Autocomplete(props) {
64
65
  const { className, inputWrapperClassName, value, onChange, size = 'm', getOptions, onSelect, debounceDelay = 300, round = false, blur = false, inputProps = {}, popupProps = {}, menuProps = {}, } = props;
@@ -1,48 +1,19 @@
1
1
  import { jsxs, jsx } from 'react/jsx-runtime';
2
- import { Component } from 'react';
3
2
  import cn from 'classnames';
4
- import { createStore } from 'justorm/react';
5
3
  import { Icon } from '../Icon/Icon.js';
6
- import { generateUID } from '../../tools/uid.js';
4
+ import 'react';
5
+ import 'timen';
6
+ import { useToggleState } from '../../hooks/useToggleState.js';
7
7
  import S from './Checkbox.styl.js';
8
8
 
9
- class Checkbox extends Component {
10
- id;
11
- store;
12
- static defaultProps = {
13
- size: 'm',
14
- variant: 'default',
15
- label: '',
16
- checked: false,
17
- };
18
- constructor(props) {
19
- super(props);
20
- this.id = props.id || generateUID();
21
- this.store = createStore(this, { isActive: false, isFocused: false });
22
- }
23
- onMouseDown = () => {
24
- this.store.isActive = true;
25
- };
26
- onMouseUp = () => {
27
- this.store.isActive = false;
28
- };
29
- onFocus = (e) => {
30
- const { onFocus } = this.props;
31
- this.store.isFocused = true;
32
- onFocus?.(e);
33
- };
34
- onBlur = (e) => {
35
- const { onBlur } = this.props;
36
- this.store.isFocused = false;
37
- onBlur?.(e);
38
- };
39
- render() {
40
- const { className, label, size, variant, error, ...props } = this.props;
41
- const { checked, disabled } = props;
42
- const { isActive, isFocused } = this.store;
43
- const classes = cn(S.root, S[`size-${size}`], S[`variant-${variant}`], checked && S.checked, disabled && S.disabled, error && S.hasError, isActive && S.isActive, isFocused && S.isFocused, className);
44
- return (jsxs("label", { className: classes, onMouseDown: this.onMouseDown, onMouseUp: this.onMouseUp, children: [jsxs("div", { className: S.controlWrapper, children: [jsx("input", { className: S.control, ...props, onFocus: this.onFocus, onBlur: this.onBlur, id: this.id, type: "checkbox", tabIndex: 0 }), jsx(Icon, { type: "check", className: S.checkmark, size: size })] }), label] }));
45
- }
46
- }
9
+ const Checkbox = ({ className, label = '', size = 'm', variant = 'default', error, checked = false, disabled, id, onFocus, onBlur, ...props }) => {
10
+ const { id: componentId, isActive, isFocused, handlers, } = useToggleState({
11
+ id,
12
+ onFocus,
13
+ onBlur,
14
+ });
15
+ const classes = cn(S.root, S[`size-${size}`], S[`variant-${variant}`], checked && S.checked, disabled && S.disabled, error && S.hasError, isActive && S.isActive, isFocused && S.isFocused, className);
16
+ return (jsxs("label", { className: classes, onPointerDown: handlers.onPointerDown, onPointerUp: handlers.onPointerUp, children: [jsxs("div", { className: S.controlWrapper, children: [jsx("input", { className: S.control, ...props, onFocus: handlers.onFocus, onBlur: handlers.onBlur, id: componentId, type: "checkbox", checked: checked, disabled: disabled, tabIndex: 0 }), jsx(Icon, { type: "check", className: S.checkmark, size: size })] }), label] }));
17
+ };
47
18
 
48
19
  export { Checkbox };
@@ -57,6 +57,7 @@ import '../Text/Text.js';
57
57
  import '../Virtualized/Virtualized.styl.js';
58
58
  import '../Virtualized/List/List.styl.js';
59
59
  import '../Virtualized/List/ListScroll.styl.js';
60
+ import '../Toggle/Toggle.styl.js';
60
61
  import '../../services/i18n.js';
61
62
 
62
63
  const SCROLL_OFFSET = {
@@ -0,0 +1,18 @@
1
+ import { jsxs, jsx } from 'react/jsx-runtime';
2
+ import cn from 'classnames';
3
+ import { useToggleState } from '../../hooks/useToggleState.js';
4
+ import S from './Toggle.styl.js';
5
+
6
+ function Toggle(props) {
7
+ const { className, label, size = 'm', variant = 'default', error, ...inputProps } = props;
8
+ const { checked, disabled } = inputProps;
9
+ const { id, isActive, isFocused, handlers } = useToggleState(props);
10
+ const classes = cn(S.root, S[`size-${size}`], S[`variant-${variant}`], checked && S.checked, disabled && S.disabled,
11
+ // error && S.hasError,
12
+ isActive && S.isActive,
13
+ // isFocused && S.isFocused,
14
+ className);
15
+ return (jsxs("label", { className: classes, onPointerDown: handlers.onPointerDown, onPointerUp: handlers.onPointerUp, children: [jsxs("div", { className: S.toggleWrapper, children: [jsx("input", { className: S.control, ...inputProps, onFocus: handlers.onFocus, onBlur: handlers.onBlur, id: id, type: "checkbox", tabIndex: 0 }), jsx("div", { className: S.track, children: jsx("div", { className: S.thumb }) })] }), label && jsx("span", { className: S.label, children: label })] }));
16
+ }
17
+
18
+ export { Toggle };
@@ -0,0 +1,7 @@
1
+ import styleInject from '../../../node_modules/style-inject/dist/style-inject.es.js';
2
+
3
+ var css_248z = ".Toggle_root__oTmAc{align-items:center;box-sizing:border-box;color:inherit;cursor:pointer;display:inline-flex;gap:.5em;-webkit-user-select:none;-moz-user-select:none;user-select:none}.Toggle_disabled__tFhaN{opacity:.4;pointer-events:none}.Toggle_toggleWrapper__CAd-a{display:block;position:relative;transition:.2s ease-out;transition-property:opacity,box-shadow}.Toggle_control__umhAB{-webkit-appearance:none;-moz-appearance:none;appearance:none;box-shadow:inset 0 0 0 2px none;box-sizing:border-box;opacity:0;pointer-events:none;position:absolute;transition:.2s ease-out;transition-property:background-color,box-shadow,opacity}.Toggle_control__umhAB:focus,.Toggle_control__umhAB:hover{background-color:var(--active-color-alpha-100)}.Toggle_control__umhAB[disabled]{background-color:var(--accent-color-alpha-100);opacity:.4;pointer-events:none}.Toggle_track__8HXVK{background-color:var(--accent-color-alpha-100);border-radius:100px;cursor:pointer;padding:2px;position:relative;transition:.3s ease-out;transition-property:background-color,border-color}.Toggle_checked__E4mPh .Toggle_track__8HXVK{background-color:var(--active-color)}.Toggle_isActive__Rx-Bv .Toggle_track__8HXVK,.Toggle_isFocused__LIHbP .Toggle_track__8HXVK{background-color:var(--active-color-alpha-500)}.Toggle_thumb__MrfWx{background-color:var(--accent-color-alpha-900);border-radius:50%;box-shadow:0 2px 4px rgba(0,0,0,.2);opacity:.9;transition:.2s ease-out;transition-property:transform,opacity}.Toggle_isActive__Rx-Bv .Toggle_thumb__MrfWx,.Toggle_root__oTmAc:hover .Toggle_thumb__MrfWx{opacity:1}.Toggle_label__eLVN-{font-size:inherit;line-height:inherit}.Toggle_size-s__NZkE5 .Toggle_track__8HXVK{height:30px;width:51px}.Toggle_size-s__NZkE5 .Toggle_thumb__MrfWx{height:26px;width:26px}.Toggle_checked__E4mPh.Toggle_size-s__NZkE5 .Toggle_thumb__MrfWx{transform:translateX(21px)}.Toggle_size-m__c2T-w .Toggle_track__8HXVK{height:40px;width:68px}.Toggle_size-m__c2T-w .Toggle_thumb__MrfWx{height:36px;width:36px}.Toggle_checked__E4mPh.Toggle_size-m__c2T-w .Toggle_thumb__MrfWx{transform:translateX(28px)}.Toggle_size-l__LhLRR .Toggle_track__8HXVK{height:50px;width:85px}.Toggle_size-l__LhLRR .Toggle_thumb__MrfWx{height:46px;width:46px}.Toggle_checked__E4mPh.Toggle_size-l__LhLRR .Toggle_thumb__MrfWx{transform:translateX(35px)}";
4
+ var S = {"root":"Toggle_root__oTmAc","disabled":"Toggle_disabled__tFhaN","toggleWrapper":"Toggle_toggleWrapper__CAd-a","control":"Toggle_control__umhAB","track":"Toggle_track__8HXVK","checked":"Toggle_checked__E4mPh","isActive":"Toggle_isActive__Rx-Bv","isFocused":"Toggle_isFocused__LIHbP","thumb":"Toggle_thumb__MrfWx","label":"Toggle_label__eLVN-","size-s":"Toggle_size-s__NZkE5","size-m":"Toggle_size-m__c2T-w","size-l":"Toggle_size-l__LhLRR"};
5
+ styleInject(css_248z);
6
+
7
+ export { S as default };
@@ -0,0 +1,35 @@
1
+ import { useState, useCallback } from 'react';
2
+ import { generateUID } from '../tools/uid.js';
3
+
4
+ function useToggleState(props = {}) {
5
+ const id = props.id || generateUID();
6
+ const [isActive, setIsActive] = useState(false);
7
+ const [isFocused, setIsFocused] = useState(false);
8
+ const onPointerDown = useCallback(() => {
9
+ setIsActive(true);
10
+ }, []);
11
+ const onPointerUp = useCallback(() => {
12
+ setIsActive(false);
13
+ }, []);
14
+ const onFocus = useCallback((e) => {
15
+ setIsFocused(true);
16
+ props.onFocus?.(e);
17
+ }, [props.onFocus]);
18
+ const onBlur = useCallback((e) => {
19
+ setIsFocused(false);
20
+ props.onBlur?.(e);
21
+ }, [props.onBlur]);
22
+ return {
23
+ id,
24
+ isActive,
25
+ isFocused,
26
+ handlers: {
27
+ onPointerDown,
28
+ onPointerUp,
29
+ onFocus,
30
+ onBlur,
31
+ },
32
+ };
33
+ }
34
+
35
+ export { useToggleState };
@@ -1,18 +1,3 @@
1
- import { Component } from 'react';
1
+ import { FC } from 'react';
2
2
  import * as T from './Checkbox.types';
3
- export declare class Checkbox extends Component<T.Props> {
4
- id: any;
5
- store: any;
6
- static defaultProps: {
7
- size: string;
8
- variant: string;
9
- label: string;
10
- checked: boolean;
11
- };
12
- constructor(props: any);
13
- onMouseDown: () => void;
14
- onMouseUp: () => void;
15
- onFocus: (e: any) => void;
16
- onBlur: (e: any) => void;
17
- render(): JSX.Element;
18
- }
3
+ export declare const Checkbox: FC<T.Props>;
@@ -1,5 +1,6 @@
1
1
  import * as T from './Icon.types';
2
2
  export declare const icons: {
3
+ attach: () => Promise<any>;
3
4
  arrowRight: () => Promise<any>;
4
5
  arrowLeft: () => Promise<any>;
5
6
  arrowUp: () => Promise<any>;
@@ -49,6 +50,8 @@ export declare const icons: {
49
50
  layers: () => Promise<any>;
50
51
  link: () => Promise<any>;
51
52
  loader: () => Promise<any>;
53
+ lock: () => Promise<any>;
54
+ lockOpen: () => Promise<any>;
52
55
  map: () => Promise<any>;
53
56
  menu: () => Promise<any>;
54
57
  mic: () => Promise<any>;
@@ -73,6 +76,7 @@ export declare const icons: {
73
76
  send: () => Promise<any>;
74
77
  settings: () => Promise<any>;
75
78
  shoppingBag: () => Promise<any>;
79
+ smile: () => Promise<any>;
76
80
  soundWave: () => Promise<any>;
77
81
  sparks: () => Promise<any>;
78
82
  star: () => Promise<any>;
@@ -0,0 +1,3 @@
1
+ import * as T from './Toggle.types';
2
+ export type ToggleProps = T.Props;
3
+ export declare function Toggle(props: ToggleProps): JSX.Element;
@@ -0,0 +1,10 @@
1
+ import { ReactNode, HTMLAttributes } from 'react';
2
+ import { Size, ComponentType } from '../../types';
3
+ export type Props = HTMLAttributes<HTMLInputElement> & ComponentType & {
4
+ label?: ReactNode;
5
+ checked?: boolean;
6
+ disabled?: boolean;
7
+ error?: string | boolean;
8
+ size?: Size;
9
+ variant?: 'default' | 'outlined';
10
+ };
@@ -42,3 +42,4 @@ export * from './Text/Text';
42
42
  export * from './Theme/Theme';
43
43
  export * from './VH/VH';
44
44
  export * from './Virtualized';
45
+ export * from './Toggle/Toggle';
@@ -4,3 +4,4 @@ export * from './useEvent';
4
4
  export * from './useIsMounted';
5
5
  export * from './useListKeyboardControl';
6
6
  export * from './useResizeObserver';
7
+ export * from './useToggleState';
@@ -0,0 +1,17 @@
1
+ export interface UseToggleStateProps {
2
+ id?: string;
3
+ onFocus?: (e: any) => void;
4
+ onBlur?: (e: any) => void;
5
+ }
6
+ export interface UseToggleState {
7
+ id: string;
8
+ isActive: boolean;
9
+ isFocused: boolean;
10
+ handlers: {
11
+ onPointerDown: () => void;
12
+ onPointerUp: () => void;
13
+ onFocus: (e: any) => void;
14
+ onBlur: (e: any) => void;
15
+ };
16
+ }
17
+ export declare function useToggleState(props?: UseToggleStateProps): UseToggleState;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@homecode/ui",
3
- "version": "4.26.10",
3
+ "version": "4.27.0",
4
4
  "description": "React UI components library",
5
5
  "scripts": {
6
6
  "tests": "jest",