@glimstone/react 4.2.2 → 4.2.3
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/Toggle.d.ts +7 -2
- package/dist/Toggle.js +17 -6
- package/package.json +2 -2
package/dist/Toggle.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type ButtonHTMLAttributes } from "react";
|
|
2
2
|
export interface ToggleProps extends Omit<ButtonHTMLAttributes<HTMLButtonElement>, "onChange" | "children" | "type" | "role"> {
|
|
3
3
|
/** Current on/off state. */
|
|
4
4
|
checked: boolean;
|
|
@@ -11,7 +11,12 @@ export interface ToggleProps extends Omit<ButtonHTMLAttributes<HTMLButtonElement
|
|
|
11
11
|
* because a card title further up already says it. */
|
|
12
12
|
hideLabel?: boolean;
|
|
13
13
|
disabled?: boolean;
|
|
14
|
+
/** Why the switch cannot be flipped right now, as OLED while Light is chosen
|
|
15
|
+
* (`oledRefusal`). It keeps its state and its focus, its track dims, a press
|
|
16
|
+
* shakes it, and the reason is its bubble, or a line under the row on a
|
|
17
|
+
* touch screen. */
|
|
18
|
+
refused?: string;
|
|
14
19
|
/** Extra classes for the outer wrapper (e.g. row-alignment nudges). */
|
|
15
20
|
className?: string;
|
|
16
21
|
}
|
|
17
|
-
export declare function Toggle({ checked, onChange, label, hideLabel, disabled, className, style, onClick, ...rest }: ToggleProps): import("react").JSX.Element;
|
|
22
|
+
export declare function Toggle({ checked, onChange, label, hideLabel, disabled, refused, className, style, onClick, ...rest }: ToggleProps): import("react").JSX.Element;
|
package/dist/Toggle.js
CHANGED
|
@@ -1,9 +1,20 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useId, useRef, useState } from "react";
|
|
3
|
+
import { shake } from "@glimstone/core";
|
|
2
4
|
import { useFieldName } from "./fieldName.js";
|
|
3
|
-
|
|
5
|
+
import { useTipBubble } from "./useTipBubble.js";
|
|
6
|
+
export function Toggle({ checked, onChange, label, hideLabel = false, disabled, refused, className, style, onClick, ...rest }) {
|
|
4
7
|
const name = useFieldName(label);
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
const frame = useRef(null);
|
|
9
|
+
const [shakes, setShakes] = useState(0);
|
|
10
|
+
useEffect(() => (shakes > 0 ? shake(frame.current) : undefined), [shakes]);
|
|
11
|
+
const tip = useTipBubble(refused);
|
|
12
|
+
const reason = useId();
|
|
13
|
+
return (_jsxs(_Fragment, { children: [_jsxs("span", { ref: frame, className: `glim-toggle${className ? ` ${className}` : ""}`, style: style, children: [label !== undefined && !hideLabel && _jsx("span", { className: "glim-toggle-label", children: label }), _jsx("button", { ...rest, ...(refused ? tip.handlers : {}), ref: tip.ref, type: "button", role: "switch", "aria-checked": checked, "aria-label": name, "aria-disabled": refused ? true : undefined, "aria-describedby": refused ? reason : rest["aria-describedby"], disabled: disabled, onClick: (e) => {
|
|
14
|
+
onClick?.(e);
|
|
15
|
+
if (refused)
|
|
16
|
+
setShakes((n) => n + 1);
|
|
17
|
+
else
|
|
18
|
+
onChange(!checked);
|
|
19
|
+
}, className: "glim-toggle-track", children: _jsx("span", { className: "glim-toggle-thumb" }) })] }), refused && (_jsx("span", { id: reason, className: "glim-toggle-refusal", children: refused })), tip.bubble] }));
|
|
9
20
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@glimstone/react",
|
|
3
|
-
"version": "4.2.
|
|
3
|
+
"version": "4.2.3",
|
|
4
4
|
"description": "GlimStone's components for React",
|
|
5
5
|
"license": "AGPL-3.0-only",
|
|
6
6
|
"repository": { "type": "git", "url": "git+https://github.com/junkerderprovinz/glimstone.git", "directory": "packages/react" },
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"build": "tsc -p tsconfig.build.json"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@glimstone/core": "4.2.
|
|
19
|
+
"@glimstone/core": "4.2.3"
|
|
20
20
|
},
|
|
21
21
|
"peerDependencies": {
|
|
22
22
|
"@zag-js/combobox": "^1.46.0",
|