mosuk-ui 1.0.10 → 1.0.12
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/components/actions/input/(otp)/component/component.d.ts +3 -0
- package/components/actions/input/(otp)/component/component.interface.d.ts +6 -0
- package/components/actions/input/(otp)/component/component.js +33 -0
- package/components/actions/input/(otp)/component/component.module.css +49 -0
- package/components/actions/input/(otp)/component/field/component.d.ts +7 -0
- package/components/actions/input/(otp)/component/field/component.js +30 -0
- package/components/actions/input/(otp)/component/index.d.ts +13 -0
- package/components/actions/input/(otp)/component/index.js +7 -0
- package/components/actions/input/(otp)/component/separator/component.d.ts +7 -0
- package/components/actions/input/(otp)/component/separator/component.js +30 -0
- package/components/actions/input/(otp)/skeleton/component.d.ts +3 -0
- package/components/actions/{toggle/skeleton/component.props.d.ts → input/(otp)/skeleton/component.interface.d.ts} +2 -1
- package/components/actions/{toggle → input/(otp)}/skeleton/component.js +3 -3
- package/components/actions/input/(otp)/skeleton/component.module.css +18 -0
- package/components/actions/input/(otp)/skeleton/index.d.ts +6 -0
- package/components/actions/input/(otp)/skeleton/index.js +2 -0
- package/components/actions/toggle/component/{button → .partials/components/button}/component.js +3 -3
- package/components/actions/toggle/component/{component.d.ts → .partials/components/component.d.ts} +1 -1
- package/components/actions/toggle/component/{component.js → .partials/components/component.js} +14 -14
- package/components/actions/toggle/component/{component.props.d.ts → .partials/components/component.props.d.ts} +3 -1
- package/components/actions/toggle/component/{indicator → .partials/components/indicator}/component.js +34 -16
- package/components/actions/toggle/component/.partials/providers/context/context.interface.d.ts +10 -0
- package/components/actions/toggle/component/{providers → .partials/providers}/provider.d.ts +1 -1
- package/components/actions/toggle/component/{providers → .partials/providers}/provider.interface.d.ts +2 -0
- package/components/actions/toggle/component/.partials/providers/provider.js +92 -0
- package/components/actions/toggle/component/.partials/styles/component.module.css +120 -0
- package/components/actions/toggle/component/.partials/utilities/scroll-toggle-option-into-view.d.ts +8 -0
- package/components/actions/toggle/component/.partials/utilities/scroll-toggle-option-into-view.js +69 -0
- package/components/actions/toggle/component/index.d.ts +6 -6
- package/components/actions/toggle/component/index.js +3 -3
- package/components/actions/toggle/skeleton/{button → .partials/components/button}/component.js +2 -2
- package/components/actions/toggle/skeleton/.partials/components/button/component.props.js +1 -0
- package/components/actions/toggle/skeleton/{component.d.ts → .partials/components/component.d.ts} +1 -1
- package/components/actions/toggle/skeleton/.partials/components/component.js +30 -0
- package/components/actions/toggle/skeleton/.partials/components/component.props.d.ts +6 -0
- package/components/actions/toggle/skeleton/.partials/components/component.props.js +1 -0
- package/components/actions/toggle/skeleton/{component.module.css → .partials/styles/component.module.css} +32 -7
- package/components/actions/toggle/skeleton/index.d.ts +4 -4
- package/components/actions/toggle/skeleton/index.js +2 -2
- package/components/overlays/drawer/component/component.module.css +1 -1
- package/components/overlays/dropdown/component/component.js +1 -2
- package/components/overlays/dropdown/component/component.module.css +2 -2
- package/components/texts/counter/component/component.js +55 -12
- package/package.json +16 -6
- package/styles/components/actions/button/[size]/style.css +11 -265
- package/styles/components/actions/icon/[size]/style.css +12 -290
- package/styles/components/actions/input/[size]/style.css +18 -76
- package/styles/utilities/action/fill/style.css +1 -3
- package/styles/utilities/action/glass/style.css +0 -2
- package/styles/utilities/action/outline/style.css +1 -0
- package/styles/utilities/action/style.css +1 -2
- package/components/actions/toggle/component/component.module.css +0 -80
- package/components/actions/toggle/component/providers/context/context.interface.d.ts +0 -7
- package/components/actions/toggle/component/providers/provider.js +0 -34
- package/styles/utilities/action/transparent/style.css +0 -5
- /package/components/actions/{toggle/component/button/component.props.js → input/(otp)/component/component.interface.js} +0 -0
- /package/components/actions/{toggle/component/component.props.js → input/(otp)/skeleton/component.interface.js} +0 -0
- /package/components/actions/toggle/component/{button → .partials/components/button}/component.d.ts +0 -0
- /package/components/actions/toggle/component/{button → .partials/components/button}/component.props.d.ts +0 -0
- /package/components/actions/toggle/component/{indicator → .partials/components/button}/component.props.js +0 -0
- /package/components/actions/toggle/{skeleton/button → component/.partials/components}/component.props.js +0 -0
- /package/components/actions/toggle/component/{indicator → .partials/components/indicator}/component.d.ts +0 -0
- /package/components/actions/toggle/component/{indicator → .partials/components/indicator}/component.props.d.ts +0 -0
- /package/components/actions/toggle/{skeleton → component/.partials/components/indicator}/component.props.js +0 -0
- /package/components/actions/toggle/component/{hooks → .partials/hooks}/hook.d.ts +0 -0
- /package/components/actions/toggle/component/{hooks → .partials/hooks}/hook.js +0 -0
- /package/components/actions/toggle/component/{providers → .partials/providers}/context/context.d.ts +0 -0
- /package/components/actions/toggle/component/{providers → .partials/providers}/context/context.interface.js +0 -0
- /package/components/actions/toggle/component/{providers → .partials/providers}/context/context.js +0 -0
- /package/components/actions/toggle/component/{providers → .partials/providers}/provider.interface.js +0 -0
- /package/components/actions/toggle/skeleton/{button → .partials/components/button}/component.d.ts +0 -0
- /package/components/actions/toggle/skeleton/{button → .partials/components/button}/component.props.d.ts +0 -0
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ComponentPropsWithoutRef, ElementType, Ref } from 'react';
|
|
2
|
+
import { OTPFieldPreview as BaseOTPField } from '@base-ui/react/otp-field';
|
|
3
|
+
export type InputOtpProps<C extends ElementType = 'div'> = {
|
|
4
|
+
as?: C;
|
|
5
|
+
ref?: Ref<any>;
|
|
6
|
+
} & Omit<ComponentPropsWithoutRef<C>, 'as' | 'ref'> & Omit<BaseOTPField.Root.Props, 'className' | 'style'>;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
13
|
+
var t = {};
|
|
14
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
15
|
+
t[p] = s[p];
|
|
16
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
17
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
18
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
19
|
+
t[p[i]] = s[p[i]];
|
|
20
|
+
}
|
|
21
|
+
return t;
|
|
22
|
+
};
|
|
23
|
+
import classNames from 'classnames';
|
|
24
|
+
import React, { useId } from 'react';
|
|
25
|
+
import { OTPFieldPreview as OTPField } from '@base-ui/react/otp-field';
|
|
26
|
+
import styles from './component.module.css';
|
|
27
|
+
export function InputOtp(_a) {
|
|
28
|
+
var _b;
|
|
29
|
+
var as = _a.as, children = _a.children, length = _a.length, rest = __rest(_a, ["as", "children", "length"]);
|
|
30
|
+
var Component = (as || OTPField.Root);
|
|
31
|
+
var id = (_b = rest === null || rest === void 0 ? void 0 : rest.id) !== null && _b !== void 0 ? _b : useId();
|
|
32
|
+
return (React.createElement(Component, __assign({}, rest, { id: id, length: length, className: classNames(styles.root, 'mosuk-input-otp', rest === null || rest === void 0 ? void 0 : rest.className) }), children));
|
|
33
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
@layer mosuk-ui {
|
|
2
|
+
@layer index-11 {
|
|
3
|
+
.root {
|
|
4
|
+
display: flex;
|
|
5
|
+
width: 100%;
|
|
6
|
+
gap: var(--spacing-2, calc(var(--spacing, 0.25rem) * 2));
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
.input {
|
|
10
|
+
box-sizing: border-box;
|
|
11
|
+
margin: 0;
|
|
12
|
+
height: var(--spacing-11, calc(var(--spacing, 0.25rem) * 11));
|
|
13
|
+
width: var(--spacing-10, calc(var(--spacing, 0.25rem) * 10));
|
|
14
|
+
border-radius: var(--radius-lg, calc(var(--spacing, 0.25rem) * 2));
|
|
15
|
+
border: 1px solid var(--color-gray-300, rgb(209 213 219));
|
|
16
|
+
background-color: transparent;
|
|
17
|
+
text-align: center;
|
|
18
|
+
font-family: inherit;
|
|
19
|
+
font-size: var(--text-xl, calc(var(--spacing, 0.25rem) * 4.5));
|
|
20
|
+
font-weight: var(--font-medium, 500);
|
|
21
|
+
color: var(--color-black, #000);
|
|
22
|
+
outline: none;
|
|
23
|
+
transition: all 200ms ease-in-out;
|
|
24
|
+
|
|
25
|
+
&::placeholder {
|
|
26
|
+
color: var(--color-gray-500, oklch(0.551 0.027 264.364));
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
&:focus {
|
|
30
|
+
outline: none;
|
|
31
|
+
border-color: var(--color-blue-500, oklch(0.623 0.214 259.815));
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
&:read-only {
|
|
35
|
+
opacity: 50%;
|
|
36
|
+
pointer-events: none;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
.separator {
|
|
41
|
+
display: flex;
|
|
42
|
+
align-items: center;
|
|
43
|
+
justify-content: center;
|
|
44
|
+
color: var(--color-gray-500, oklch(0.551 0.027 264.364));
|
|
45
|
+
font-size: var(--text-xl, calc(var(--spacing, 0.25rem) * 4.5));
|
|
46
|
+
font-weight: var(--font-medium, 500);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { OTPFieldInputProps } from "@base-ui/react";
|
|
3
|
+
export interface InputOtpFieldProps extends OTPFieldInputProps {
|
|
4
|
+
index?: number;
|
|
5
|
+
length?: number;
|
|
6
|
+
}
|
|
7
|
+
export declare function InputOtpField({ index, length, className, ...rest }: InputOtpFieldProps): React.JSX.Element;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
13
|
+
var t = {};
|
|
14
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
15
|
+
t[p] = s[p];
|
|
16
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
17
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
18
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
19
|
+
t[p[i]] = s[p[i]];
|
|
20
|
+
}
|
|
21
|
+
return t;
|
|
22
|
+
};
|
|
23
|
+
import classNames from 'classnames';
|
|
24
|
+
import React from 'react';
|
|
25
|
+
import { OTPFieldPreview as OTPField } from '@base-ui/react/otp-field';
|
|
26
|
+
import styles from '../component.module.css';
|
|
27
|
+
export function InputOtpField(_a) {
|
|
28
|
+
var index = _a.index, length = _a.length, className = _a.className, rest = __rest(_a, ["index", "length", "className"]);
|
|
29
|
+
return (React.createElement(OTPField.Input, __assign({ className: classNames(styles.input, 'mosuk-input-otp-field', className), "aria-label": "Character ".concat(index !== null && index !== void 0 ? index : 1, " of ").concat(length) }, rest)));
|
|
30
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { InputOtp as Component } from './component';
|
|
2
|
+
import { InputOtpProps as ComponentProps } from './component.interface';
|
|
3
|
+
import { InputOtpField, InputOtpFieldProps } from './field/component';
|
|
4
|
+
import { InputOtpSeparator, InputOtpSeparatorProps } from './separator/component';
|
|
5
|
+
export declare const InputOtp: typeof Component & {
|
|
6
|
+
Field: typeof InputOtpField;
|
|
7
|
+
Separator: typeof InputOtpSeparator;
|
|
8
|
+
};
|
|
9
|
+
export declare namespace InputOtp {
|
|
10
|
+
type Props = ComponentProps;
|
|
11
|
+
type FieldProps = InputOtpFieldProps;
|
|
12
|
+
type SeparatorProps = InputOtpSeparatorProps;
|
|
13
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { InputOtp as Component } from './component';
|
|
2
|
+
import { InputOtpField } from './field/component';
|
|
3
|
+
import { InputOtpSeparator } from './separator/component';
|
|
4
|
+
export var InputOtp = Object.assign(Component, {
|
|
5
|
+
Field: InputOtpField,
|
|
6
|
+
Separator: InputOtpSeparator,
|
|
7
|
+
});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { SeparatorProps } from "@base-ui/react";
|
|
3
|
+
export interface InputOtpSeparatorProps extends SeparatorProps {
|
|
4
|
+
index?: number;
|
|
5
|
+
length?: number;
|
|
6
|
+
}
|
|
7
|
+
export declare function InputOtpSeparator({ index, length, className, ...rest }: InputOtpSeparatorProps): React.JSX.Element;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
13
|
+
var t = {};
|
|
14
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
15
|
+
t[p] = s[p];
|
|
16
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
17
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
18
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
19
|
+
t[p[i]] = s[p[i]];
|
|
20
|
+
}
|
|
21
|
+
return t;
|
|
22
|
+
};
|
|
23
|
+
import classNames from 'classnames';
|
|
24
|
+
import React from 'react';
|
|
25
|
+
import { OTPFieldPreview as OTPField } from '@base-ui/react/otp-field';
|
|
26
|
+
import styles from '../component.module.css';
|
|
27
|
+
export function InputOtpSeparator(_a) {
|
|
28
|
+
var index = _a.index, length = _a.length, className = _a.className, rest = __rest(_a, ["index", "length", "className"]);
|
|
29
|
+
return (React.createElement(OTPField.Separator, __assign({ className: classNames(styles.separator, 'mosuk-input-otp-separator', className), "aria-label": "Character ".concat(index !== null && index !== void 0 ? index : 1, " of ").concat(length) }, rest)));
|
|
30
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ComponentPropsWithoutRef, ElementType, Ref } from 'react';
|
|
2
|
-
export type
|
|
2
|
+
export type InputOtpSkeletonProps<C extends ElementType = 'div'> = {
|
|
3
3
|
as?: C;
|
|
4
4
|
ref?: Ref<any>;
|
|
5
|
+
slots?: number;
|
|
5
6
|
} & Omit<ComponentPropsWithoutRef<C>, 'as' | 'ref'>;
|
|
@@ -23,8 +23,8 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
23
23
|
import classNames from 'classnames';
|
|
24
24
|
import React from 'react';
|
|
25
25
|
import styles from './component.module.css';
|
|
26
|
-
export function
|
|
27
|
-
var as = _a.as, rest = __rest(_a, ["as"]);
|
|
26
|
+
export function InputOtpSkeleton(_a) {
|
|
27
|
+
var as = _a.as, _b = _a.slots, slots = _b === void 0 ? 6 : _b, children = _a.children, rest = __rest(_a, ["as", "slots", "children"]);
|
|
28
28
|
var Component = (as || 'div');
|
|
29
|
-
return (React.createElement(Component, __assign({}, rest, { className: classNames('mosuk-
|
|
29
|
+
return (React.createElement(Component, __assign({}, rest, { className: classNames('mosuk-input-otp-skeleton', styles.otp, rest === null || rest === void 0 ? void 0 : rest.className) }), children));
|
|
30
30
|
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
@layer mosuk-ui {
|
|
2
|
+
@layer index-11 {
|
|
3
|
+
.otp {
|
|
4
|
+
display: flex;
|
|
5
|
+
gap: calc(var(--spacing, .25rem) * 2);
|
|
6
|
+
width: 100%;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
.slot {
|
|
10
|
+
width: calc(var(--spacing, .25rem) * 10);
|
|
11
|
+
height: calc(var(--spacing, .25rem) * 10);
|
|
12
|
+
min-width: calc(var(--spacing, .25rem) * 10);
|
|
13
|
+
min-height: calc(var(--spacing, .25rem) * 10);
|
|
14
|
+
|
|
15
|
+
border-radius: calc(var(--spacing, .25rem) * 2);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { InputOtpSkeleton as Component } from './component';
|
|
2
|
+
import { InputOtpSkeletonProps as ComponentProps } from './component.interface';
|
|
3
|
+
export declare const InputOtpSkeleton: typeof Component;
|
|
4
|
+
export declare namespace InputOtpSkeleton {
|
|
5
|
+
type Props = ComponentProps;
|
|
6
|
+
}
|
package/components/actions/toggle/component/{button → .partials/components/button}/component.js
RENAMED
|
@@ -22,9 +22,9 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
22
22
|
};
|
|
23
23
|
import classNames from 'classnames';
|
|
24
24
|
import React, { useCallback } from 'react';
|
|
25
|
-
import { Button } from '
|
|
26
|
-
import
|
|
27
|
-
import
|
|
25
|
+
import { Button } from '../../../../../button/component/component';
|
|
26
|
+
import { useToggle } from '../../hooks/hook';
|
|
27
|
+
import styles from '../../styles/component.module.css';
|
|
28
28
|
export function ToggleButton(_a) {
|
|
29
29
|
var _b;
|
|
30
30
|
var as = _a.as, value = _a.value, rest = __rest(_a, ["as", "value"]);
|
package/components/actions/toggle/component/{component.d.ts → .partials/components/component.d.ts}
RENAMED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import React, { ElementType } from 'react';
|
|
2
2
|
import { ToggleProps } from './component.props';
|
|
3
|
-
export declare function Toggle<C extends ElementType = 'div'>({ as, value, onChange, className, onClickCapture, ref, ...rest }: ToggleProps<C>): React.JSX.Element;
|
|
3
|
+
export declare function Toggle<C extends ElementType = 'div'>({ as, value, onChange, orientation, className, onClickCapture, ref, ...rest }: ToggleProps<C>): React.JSX.Element;
|
package/components/actions/toggle/component/{component.js → .partials/components/component.js}
RENAMED
|
@@ -22,10 +22,11 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
22
22
|
};
|
|
23
23
|
import classNames from 'classnames';
|
|
24
24
|
import React, { useCallback, useEffect, useRef } from 'react';
|
|
25
|
-
import
|
|
26
|
-
import
|
|
25
|
+
import { ToggleProvider } from '../providers/provider';
|
|
26
|
+
import styles from '../styles/component.module.css';
|
|
27
|
+
import { scrollToggleOptionIntoView } from '../utilities/scroll-toggle-option-into-view';
|
|
27
28
|
export function Toggle(_a) {
|
|
28
|
-
var as = _a.as, value = _a.value, onChange = _a.onChange, className = _a.className, onClickCapture = _a.onClickCapture, ref = _a.ref, rest = __rest(_a, ["as", "value", "onChange", "className", "onClickCapture", "ref"]);
|
|
29
|
+
var as = _a.as, value = _a.value, onChange = _a.onChange, _b = _a.orientation, orientation = _b === void 0 ? 'horizontal' : _b, className = _a.className, onClickCapture = _a.onClickCapture, ref = _a.ref, rest = __rest(_a, ["as", "value", "onChange", "orientation", "className", "onClickCapture", "ref"]);
|
|
29
30
|
var Component = (as || 'div');
|
|
30
31
|
var containerRef = useRef(null);
|
|
31
32
|
var resizeObserverRef = useRef(null);
|
|
@@ -41,7 +42,12 @@ export function Toggle(_a) {
|
|
|
41
42
|
return;
|
|
42
43
|
}
|
|
43
44
|
var containerEl = containerRef.current;
|
|
44
|
-
|
|
45
|
+
var overflowsHorizontally = containerEl.scrollWidth > containerEl.clientWidth;
|
|
46
|
+
var overflowsVertically = containerEl.scrollHeight > containerEl.clientHeight;
|
|
47
|
+
var overflows = orientation === 'vertical'
|
|
48
|
+
? overflowsVertically
|
|
49
|
+
: overflowsHorizontally;
|
|
50
|
+
if (!overflows) {
|
|
45
51
|
return;
|
|
46
52
|
}
|
|
47
53
|
var optionEl = (_b = (_a = e.target) === null || _a === void 0 ? void 0 : _a.closest) === null || _b === void 0 ? void 0 : _b.call(_a, '.mosuk-toggle-button');
|
|
@@ -49,15 +55,9 @@ export function Toggle(_a) {
|
|
|
49
55
|
return;
|
|
50
56
|
}
|
|
51
57
|
requestAnimationFrame(function () {
|
|
52
|
-
|
|
53
|
-
var prefersReducedMotion = (_b = (_a = window.matchMedia) === null || _a === void 0 ? void 0 : _a.call(window, '(prefers-reduced-motion: reduce)')) === null || _b === void 0 ? void 0 : _b.matches;
|
|
54
|
-
optionEl.scrollIntoView({
|
|
55
|
-
behavior: prefersReducedMotion ? 'auto' : 'smooth',
|
|
56
|
-
block: 'nearest',
|
|
57
|
-
inline: 'nearest',
|
|
58
|
-
});
|
|
58
|
+
scrollToggleOptionIntoView(containerEl, optionEl, orientation, 'smooth');
|
|
59
59
|
});
|
|
60
|
-
}, [onClickCapture]);
|
|
60
|
+
}, [onClickCapture, orientation]);
|
|
61
61
|
var setRef = useCallback(function (node) {
|
|
62
62
|
containerRef.current = node;
|
|
63
63
|
if (typeof ref === 'function') {
|
|
@@ -84,6 +84,6 @@ export function Toggle(_a) {
|
|
|
84
84
|
el.style.setProperty('--toggle-padding', getComputedStyle(el).paddingTop);
|
|
85
85
|
}
|
|
86
86
|
}, [className]);
|
|
87
|
-
return (React.createElement(ToggleProvider, { value: value, onChange: onChange, containerRef: containerRef },
|
|
88
|
-
React.createElement(Component, __assign({}, rest, { ref: setRef, onClickCapture: handleClickCapture, className: classNames('mosuk-toggle', styles.toggle, className) }), rest === null || rest === void 0 ? void 0 : rest.children)));
|
|
87
|
+
return (React.createElement(ToggleProvider, { value: value, onChange: onChange, containerRef: containerRef, orientation: orientation },
|
|
88
|
+
React.createElement(Component, __assign({}, rest, { ref: setRef, "data-orientation": orientation, onClickCapture: handleClickCapture, className: classNames('mosuk-toggle', styles.toggle, className) }), rest === null || rest === void 0 ? void 0 : rest.children)));
|
|
89
89
|
}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { ComponentPropsWithoutRef, ElementType, Ref } from 'react';
|
|
2
|
+
import type { ToggleOrientation } from '../providers/context/context.interface';
|
|
2
3
|
export type ToggleProps<C extends ElementType = 'div'> = {
|
|
3
4
|
as?: C;
|
|
4
5
|
ref?: Ref<any>;
|
|
5
6
|
value?: any | null;
|
|
6
7
|
onChange?: (value: any) => void;
|
|
7
|
-
|
|
8
|
+
orientation?: ToggleOrientation;
|
|
9
|
+
} & Omit<ComponentPropsWithoutRef<C>, 'as' | 'ref' | 'value' | 'onChange' | 'orientation'>;
|
|
@@ -22,28 +22,38 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
22
22
|
};
|
|
23
23
|
import classNames from 'classnames';
|
|
24
24
|
import React, { useEffect, useState } from 'react';
|
|
25
|
-
import
|
|
26
|
-
import
|
|
25
|
+
import { useToggle } from '../../hooks/hook';
|
|
26
|
+
import styles from '../../styles/component.module.css';
|
|
27
27
|
export function ToggleIndicator(_a) {
|
|
28
28
|
var _b;
|
|
29
29
|
var as = _a.as, rest = __rest(_a, ["as"]);
|
|
30
30
|
var Component = (as || 'div');
|
|
31
|
-
var _c = useToggle(), value = _c.value, containerRef = _c.containerRef, optionRefs = _c.optionRefs;
|
|
32
|
-
var _d = useState(null),
|
|
31
|
+
var _c = useToggle(), value = _c.value, containerRef = _c.containerRef, optionRefs = _c.optionRefs, orientation = _c.orientation;
|
|
32
|
+
var _d = useState(null), layout = _d[0], setLayout = _d[1];
|
|
33
33
|
useEffect(function () {
|
|
34
|
-
if (
|
|
34
|
+
if (value === null || value === undefined) {
|
|
35
|
+
setLayout(null);
|
|
35
36
|
return;
|
|
36
37
|
}
|
|
37
38
|
var updatePosition = function () {
|
|
38
39
|
var el = optionRefs.current.get(value);
|
|
39
|
-
if (el) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
40
|
+
if (!el) {
|
|
41
|
+
setLayout(null);
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
if (orientation === 'vertical') {
|
|
45
|
+
setLayout({
|
|
46
|
+
orientation: 'vertical',
|
|
47
|
+
top: el.offsetTop,
|
|
48
|
+
height: el.offsetHeight,
|
|
43
49
|
});
|
|
44
50
|
}
|
|
45
51
|
else {
|
|
46
|
-
|
|
52
|
+
setLayout({
|
|
53
|
+
orientation: 'horizontal',
|
|
54
|
+
left: el.offsetLeft,
|
|
55
|
+
width: el.offsetWidth,
|
|
56
|
+
});
|
|
47
57
|
}
|
|
48
58
|
};
|
|
49
59
|
updatePosition();
|
|
@@ -71,11 +81,19 @@ export function ToggleIndicator(_a) {
|
|
|
71
81
|
resizeObserver.disconnect();
|
|
72
82
|
mutationObserver === null || mutationObserver === void 0 ? void 0 : mutationObserver.disconnect();
|
|
73
83
|
};
|
|
74
|
-
}, [value, containerRef, optionRefs]);
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
'--toggle-indicator-
|
|
78
|
-
|
|
79
|
-
|
|
84
|
+
}, [value, containerRef, optionRefs, orientation]);
|
|
85
|
+
var inlineStyle = (layout === null || layout === void 0 ? void 0 : layout.orientation) === 'vertical'
|
|
86
|
+
? {
|
|
87
|
+
'--toggle-indicator-height': "".concat(layout.height, "px"),
|
|
88
|
+
'--toggle-indicator-translate-y': "".concat(layout.top, "px"),
|
|
89
|
+
}
|
|
90
|
+
: (layout === null || layout === void 0 ? void 0 : layout.orientation) === 'horizontal'
|
|
91
|
+
? {
|
|
92
|
+
'--toggle-indicator-width': "".concat(layout.width, "px"),
|
|
93
|
+
'--toggle-indicator-translate-x': "".concat(layout.left, "px"),
|
|
94
|
+
}
|
|
95
|
+
: undefined;
|
|
96
|
+
return (React.createElement(Component, __assign({}, rest, { style: __assign(__assign({}, rest === null || rest === void 0 ? void 0 : rest.style), inlineStyle), className: classNames('mosuk-toggle-indicator', styles.indicator, (_b = {},
|
|
97
|
+
_b[styles.hidden] = value === null || value === undefined,
|
|
80
98
|
_b), rest === null || rest === void 0 ? void 0 : rest.className) })));
|
|
81
99
|
}
|
package/components/actions/toggle/component/.partials/providers/context/context.interface.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { RefObject } from 'react';
|
|
2
|
+
export type ToggleOrientation = 'horizontal' | 'vertical';
|
|
3
|
+
export interface ToggleContextProps {
|
|
4
|
+
value: any | null;
|
|
5
|
+
onChange: (value: any) => void;
|
|
6
|
+
containerRef: RefObject<HTMLElement | null>;
|
|
7
|
+
optionRefs: RefObject<Map<any, HTMLElement>>;
|
|
8
|
+
registerOption: (value: any, el: HTMLElement | null) => void;
|
|
9
|
+
orientation: ToggleOrientation;
|
|
10
|
+
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { ToggleProviderProps } from './provider.interface';
|
|
3
|
-
export declare function ToggleProvider({ value: controlledValue, onChange: controlledOnChange, containerRef, children, }: ToggleProviderProps): React.JSX.Element;
|
|
3
|
+
export declare function ToggleProvider({ value: controlledValue, onChange: controlledOnChange, containerRef, orientation, children, }: ToggleProviderProps): React.JSX.Element;
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { ReactNode, RefObject } from 'react';
|
|
2
|
+
import type { ToggleOrientation } from './context/context.interface';
|
|
2
3
|
export interface ToggleProviderProps {
|
|
3
4
|
value?: any | null;
|
|
4
5
|
onChange?: (value: any) => void;
|
|
5
6
|
containerRef?: RefObject<HTMLElement | null>;
|
|
7
|
+
orientation?: ToggleOrientation;
|
|
6
8
|
children?: ReactNode;
|
|
7
9
|
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import React, { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState, } from 'react';
|
|
3
|
+
import { scrollToggleOptionIntoView } from '../utilities/scroll-toggle-option-into-view';
|
|
4
|
+
import { ToggleContext } from './context/context';
|
|
5
|
+
export function ToggleProvider(_a) {
|
|
6
|
+
var controlledValue = _a.value, controlledOnChange = _a.onChange, containerRef = _a.containerRef, _b = _a.orientation, orientation = _b === void 0 ? 'horizontal' : _b, children = _a.children;
|
|
7
|
+
var _c = useState(null), uncontrolledValue = _c[0], setUncontrolledValue = _c[1];
|
|
8
|
+
var optionRefs = useRef(new Map());
|
|
9
|
+
var fallbackContainerRef = useRef(null);
|
|
10
|
+
var value = controlledValue !== undefined ? controlledValue : uncontrolledValue;
|
|
11
|
+
var valueRef = useRef(value);
|
|
12
|
+
var orientationRef = useRef(orientation);
|
|
13
|
+
valueRef.current = value;
|
|
14
|
+
orientationRef.current = orientation;
|
|
15
|
+
var onChange = useCallback(function (nextValue) {
|
|
16
|
+
if (controlledOnChange) {
|
|
17
|
+
controlledOnChange(nextValue);
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
setUncontrolledValue(nextValue);
|
|
21
|
+
}
|
|
22
|
+
}, [controlledOnChange]);
|
|
23
|
+
var registerOption = useCallback(function (val, el) {
|
|
24
|
+
if (el) {
|
|
25
|
+
optionRefs.current.set(val, el);
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
optionRefs.current.delete(val);
|
|
29
|
+
}
|
|
30
|
+
}, []);
|
|
31
|
+
var contextValue = useMemo(function () { return ({
|
|
32
|
+
value: value,
|
|
33
|
+
onChange: onChange,
|
|
34
|
+
containerRef: containerRef !== null && containerRef !== void 0 ? containerRef : fallbackContainerRef,
|
|
35
|
+
optionRefs: optionRefs,
|
|
36
|
+
registerOption: registerOption,
|
|
37
|
+
orientation: orientation,
|
|
38
|
+
}); }, [value, onChange, containerRef, orientation]);
|
|
39
|
+
var rootRef = containerRef !== null && containerRef !== void 0 ? containerRef : fallbackContainerRef;
|
|
40
|
+
useLayoutEffect(function () {
|
|
41
|
+
if (value === null || value === undefined) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
var cancelled = false;
|
|
45
|
+
var attempt = function (n) {
|
|
46
|
+
if (cancelled) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
var container = rootRef.current;
|
|
50
|
+
var el = optionRefs.current.get(value);
|
|
51
|
+
if (!container || !el) {
|
|
52
|
+
if (n < 12) {
|
|
53
|
+
requestAnimationFrame(function () { return attempt(n + 1); });
|
|
54
|
+
}
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
scrollToggleOptionIntoView(container, el, orientation, 'smooth');
|
|
58
|
+
};
|
|
59
|
+
attempt(0);
|
|
60
|
+
return function () {
|
|
61
|
+
cancelled = true;
|
|
62
|
+
};
|
|
63
|
+
}, [value, orientation, rootRef]);
|
|
64
|
+
useEffect(function () {
|
|
65
|
+
var container = rootRef.current;
|
|
66
|
+
if (!container) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
var runPassiveScroll = function () {
|
|
70
|
+
var v = valueRef.current;
|
|
71
|
+
if (v === null || v === undefined) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
var el = optionRefs.current.get(v);
|
|
75
|
+
if (!el) {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
requestAnimationFrame(function () {
|
|
79
|
+
scrollToggleOptionIntoView(container, el, orientationRef.current, 'auto');
|
|
80
|
+
});
|
|
81
|
+
};
|
|
82
|
+
var resizeObserver = new ResizeObserver(runPassiveScroll);
|
|
83
|
+
resizeObserver.observe(container);
|
|
84
|
+
var mutationObserver = new MutationObserver(runPassiveScroll);
|
|
85
|
+
mutationObserver.observe(container, { childList: true, subtree: true });
|
|
86
|
+
return function () {
|
|
87
|
+
resizeObserver.disconnect();
|
|
88
|
+
mutationObserver.disconnect();
|
|
89
|
+
};
|
|
90
|
+
}, [rootRef]);
|
|
91
|
+
return (React.createElement(ToggleContext.Provider, { value: contextValue }, children));
|
|
92
|
+
}
|