@tangle-network/ui 11.22.0 → 11.22.1
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/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @tangle-network/ui
|
|
2
2
|
|
|
3
|
+
## 11.22.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- eb11ddd: Switch: draw the off state as an outlined track with a filled thumb in `muted-foreground`, which clears 3:1 against the card and the canvas. The old filled `bg-input` track and `bg-background` thumb looked like one flat shape in both themes, so an unchecked switch could not be seen.
|
|
8
|
+
|
|
3
9
|
## 11.22.0
|
|
4
10
|
|
|
5
11
|
### Minor Changes
|
|
@@ -6,10 +6,10 @@ import { jsx } from "react/jsx-runtime";
|
|
|
6
6
|
import * as SwitchPrimitives from "@radix-ui/react-switch";
|
|
7
7
|
//#region src/primitives/switch.tsx
|
|
8
8
|
const Switch = React.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx(SwitchPrimitives.Root, {
|
|
9
|
-
className: cn("peer inline-flex h-5 w-9 shrink-0 cursor-pointer items-center rounded-full border-2
|
|
9
|
+
className: cn("peer inline-flex h-5 w-9 shrink-0 cursor-pointer items-center rounded-full border-2 shadow-sm transition-[background-color,border-color,box-shadow] disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:border-transparent data-[state=checked]:bg-primary data-[state=unchecked]:border-muted-foreground data-[state=unchecked]:bg-transparent", focusRing, className),
|
|
10
10
|
...props,
|
|
11
11
|
ref,
|
|
12
|
-
children: /* @__PURE__ */ jsx(SwitchPrimitives.Thumb, { className: cn("pointer-events-none block h-4 w-4 rounded-full
|
|
12
|
+
children: /* @__PURE__ */ jsx(SwitchPrimitives.Thumb, { className: cn("pointer-events-none block h-4 w-4 rounded-full shadow-lg ring-0 transition-[translate,background-color] data-[state=checked]:translate-x-4 data-[state=checked]:bg-background data-[state=unchecked]:translate-x-0 data-[state=unchecked]:bg-muted-foreground") })
|
|
13
13
|
}));
|
|
14
14
|
Switch.displayName = SwitchPrimitives.Root.displayName;
|
|
15
15
|
//#endregion
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tangle-network/ui",
|
|
3
|
-
"version": "11.22.
|
|
3
|
+
"version": "11.22.1",
|
|
4
4
|
"description": "Generic React UI components for Tangle products — primitives, chat, run, files, editor, markdown.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -149,7 +149,7 @@
|
|
|
149
149
|
"peerDependencies": {
|
|
150
150
|
"@hocuspocus/provider": ">=2.15.0 <5.0.0",
|
|
151
151
|
"@nanostores/react": ">=0.8.4 <3.0.0",
|
|
152
|
-
"@tangle-network/brand": "^1.15.
|
|
152
|
+
"@tangle-network/brand": "^1.15.4",
|
|
153
153
|
"@tiptap/core": ">=3.20.4 <4.0.0",
|
|
154
154
|
"@tiptap/extension-collaboration": ">=3.20.4 <4.0.0",
|
|
155
155
|
"@tiptap/extension-collaboration-caret": ">=3.7.0 <4.0.0",
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { cleanup, fireEvent, render, screen } from "@testing-library/react";
|
|
2
|
+
import { afterEach, describe, expect, it } from "vitest";
|
|
3
|
+
import { Switch } from "./switch";
|
|
4
|
+
|
|
5
|
+
afterEach(cleanup);
|
|
6
|
+
|
|
7
|
+
/** The classes that apply in a state: unprefixed ones, plus that state's variant. */
|
|
8
|
+
function stateClasses(el: Element, state: "checked" | "unchecked"): string[] {
|
|
9
|
+
return (el.getAttribute("class") ?? "")
|
|
10
|
+
.split(/\s+/)
|
|
11
|
+
.filter((c) => !c.startsWith("data-[") || c.startsWith(`data-[state=${state}]:`))
|
|
12
|
+
.map((c) => c.replace(`data-[state=${state}]:`, ""));
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
describe("Switch", () => {
|
|
16
|
+
it("draws its off state in muted-foreground, so an unchecked switch is visible on a card or the canvas", () => {
|
|
17
|
+
render(<Switch aria-label="Reminders" />);
|
|
18
|
+
const track = screen.getByRole("switch", { name: "Reminders" });
|
|
19
|
+
const thumb = track.firstElementChild as Element;
|
|
20
|
+
expect(track).toHaveAttribute("data-state", "unchecked");
|
|
21
|
+
expect(stateClasses(track, "unchecked")).toContain("border-muted-foreground");
|
|
22
|
+
expect(stateClasses(track, "unchecked")).not.toContain("bg-input");
|
|
23
|
+
expect(stateClasses(thumb, "unchecked")).toContain("bg-muted-foreground");
|
|
24
|
+
expect(stateClasses(thumb, "unchecked")).not.toContain("bg-background");
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it("fills the track with primary once it is on", () => {
|
|
28
|
+
render(<Switch aria-label="Reminders" />);
|
|
29
|
+
const track = screen.getByRole("switch", { name: "Reminders" });
|
|
30
|
+
fireEvent.click(track);
|
|
31
|
+
expect(track).toHaveAttribute("data-state", "checked");
|
|
32
|
+
expect(stateClasses(track, "checked")).toContain("bg-primary");
|
|
33
|
+
expect(stateClasses(track.firstElementChild as Element, "checked")).toContain("bg-background");
|
|
34
|
+
});
|
|
35
|
+
});
|
|
@@ -11,7 +11,12 @@ const Switch = React.forwardRef<
|
|
|
11
11
|
>(({ className, ...props }, ref) => (
|
|
12
12
|
<SwitchPrimitives.Root
|
|
13
13
|
className={cn(
|
|
14
|
-
|
|
14
|
+
// Off is an outlined track with a filled thumb, both in muted-foreground,
|
|
15
|
+
// which clears 3:1 against the card and the canvas in both themes (a
|
|
16
|
+
// switch's boundary is non-text content). The old bg-input track under a
|
|
17
|
+
// bg-background thumb read as one flat shape, so an off switch was not
|
|
18
|
+
// visible at all. --border-strong was tried and measured 2.2:1 on a white card.
|
|
19
|
+
"peer inline-flex h-5 w-9 shrink-0 cursor-pointer items-center rounded-full border-2 shadow-sm transition-[background-color,border-color,box-shadow] disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:border-transparent data-[state=checked]:bg-primary data-[state=unchecked]:border-muted-foreground data-[state=unchecked]:bg-transparent",
|
|
15
20
|
focusRing,
|
|
16
21
|
className,
|
|
17
22
|
)}
|
|
@@ -20,7 +25,7 @@ const Switch = React.forwardRef<
|
|
|
20
25
|
>
|
|
21
26
|
<SwitchPrimitives.Thumb
|
|
22
27
|
className={cn(
|
|
23
|
-
"pointer-events-none block h-4 w-4 rounded-full
|
|
28
|
+
"pointer-events-none block h-4 w-4 rounded-full shadow-lg ring-0 transition-[translate,background-color] data-[state=checked]:translate-x-4 data-[state=checked]:bg-background data-[state=unchecked]:translate-x-0 data-[state=unchecked]:bg-muted-foreground",
|
|
24
29
|
)}
|
|
25
30
|
/>
|
|
26
31
|
</SwitchPrimitives.Root>
|