Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@

- Dialog と Overlay のアニメーションを、モーショントークン(`--motion-*`)で動かすようにしました。`sparkle.config.json` の `motion-weight` で選んだ重さに合わせて動きます。Dialog のパネルは下から出て、中身はパネルより少し遅れてフェードインします。Overlay は閉じるとき、パネルより少し遅れて消えます。sparkle-design-cli の `motion-weight` 対応版で生成した CSS が必要です
- Modal のアニメーションも、Dialog と同じくモーショントークンで動かすようにしました。パネルは下から出て、中身(Header・Body・Footer)はパネルより少し遅れてフェードインします
- Tooltip のアニメーションをモーショントークン(Small)で動かすようにしました。表示する側に応じてアンカーの側から出て、文字は箱より少し遅れてフェードインします。文字は `data-slot="tooltip-text"` の要素で包むようになりました

### Fixed

- Tooltip の拡大の支点がアンカー側にならず、中央から拡大していた不具合を直しました。`origin-[--radix-…]` は Tailwind v4 では有効な CSS にならないため、`origin-(--radix-tooltip-content-transform-origin)` に書き換えました
- ホバーやフォーカスで色が変わるときのトランジション(`transition-colors`)をなくし、色がすぐ切り替わるようにしました。対象は Badge・Button・Card・Checkbox・IconButton・Input・Link・Radio・Select(トリガー)・Slider・Tabs です。Checkbox と Radio の選択時の色も、同じくすぐ切り替わります。状態の変化に伴う色(Switch のトラックなど)は、各コンポーネントのモーション対応で `--motion-color-*` に置き換えます

### Fixed
Expand Down
69 changes: 57 additions & 12 deletions src/components/ui/tooltip/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,11 @@ describe("Tooltip", () => {
await userEvent.hover(trigger);

const tooltipContents = await screen.findAllByText("Tooltip Content");
const visibleTooltip = tooltipContents.find(
content => content.getAttribute("data-state") === "delayed-open"
);
// 文字は tooltip-text に包まれているので、本体(tooltip-content)までさかのぼる
// en: The text is wrapped in tooltip-text, so walk up to the content element
const visibleTooltip = tooltipContents
.map(text => text.closest('[data-slot="tooltip-content"]'))
.find(content => content?.getAttribute("data-state") === "delayed-open");
expect(visibleTooltip).toBeInTheDocument();
});

Expand All @@ -66,9 +68,11 @@ describe("Tooltip", () => {

// Then: TooltipContentが表示されることを確認する
const tooltipContents = await screen.findAllByText("Tooltip Content");
const visibleTooltip = tooltipContents.find(
content => content.getAttribute("data-state") === "delayed-open"
);
// 文字は tooltip-text に包まれているので、本体(tooltip-content)までさかのぼる
// en: The text is wrapped in tooltip-text, so walk up to the content element
const visibleTooltip = tooltipContents
.map(text => text.closest('[data-slot="tooltip-content"]'))
.find(content => content?.getAttribute("data-state") === "delayed-open");
expect(visibleTooltip).toBeVisible();
});

Expand All @@ -87,9 +91,11 @@ describe("Tooltip", () => {

// Then: TooltipContentのdata-side属性がデフォルト値"top"であることを確認する
const tooltipContents = await screen.findAllByText("Tooltip Content");
const visibleTooltip = tooltipContents.find(
content => content.getAttribute("data-state") === "delayed-open"
);
// 文字は tooltip-text に包まれているので、本体(tooltip-content)までさかのぼる
// en: The text is wrapped in tooltip-text, so walk up to the content element
const visibleTooltip = tooltipContents
.map(text => text.closest('[data-slot="tooltip-content"]'))
.find(content => content?.getAttribute("data-state") === "delayed-open");
expect(visibleTooltip).toHaveAttribute("data-side", "top");
});

Expand All @@ -108,9 +114,11 @@ describe("Tooltip", () => {

// Then: TooltipContentのdata-side属性が"right"であることを確認する
const tooltipContents = await screen.findAllByText("Tooltip Content");
const visibleTooltip = tooltipContents.find(
content => content.getAttribute("data-state") === "delayed-open"
);
// 文字は tooltip-text に包まれているので、本体(tooltip-content)までさかのぼる
// en: The text is wrapped in tooltip-text, so walk up to the content element
const visibleTooltip = tooltipContents
.map(text => text.closest('[data-slot="tooltip-content"]'))
.find(content => content?.getAttribute("data-state") === "delayed-open");
expect(visibleTooltip).toHaveAttribute("data-side", "right");
});

Expand Down Expand Up @@ -139,4 +147,41 @@ describe("Tooltip", () => {
expect(arrowClass).toContain(cls)
);
});

it("animates with the Small motion tokens from the anchor side", async () => {
// Given: 上に出る Tooltip
testContainer.render(
<Tooltip>
<TooltipTrigger>Motion</TooltipTrigger>
<TooltipContent side="top">Motion Content</TooltipContent>
</Tooltip>
);

// When: ホバーして開く
await userEvent.hover(screen.getByText("Motion"));
await screen.findAllByText("Motion Content");
const content = document.querySelector(
'[data-slot="tooltip-content"]'
) as HTMLElement;

// Then: 箱は Small のトークンで、アンカーの側(下)から出る
// en: The box uses the Small motion tokens and rises from the anchor side
[
"animate-motion-pop-in-small",
"data-[state=closed]:animate-motion-pop-out-small",
"data-[side=top]:[--motion-pop-from-y:1]",
"origin-(--radix-tooltip-content-transform-origin)",
].forEach(cls => expect(content.className).toContain(cls));
expect(content.className).not.toMatch(
/\b(animate-in|animate-out|duration-\d+)\b/
);

// Then: 文字は箱より遅れてフェードインする
// en: The text fades in after the box
const text = content.querySelector(
'[data-slot="tooltip-text"]'
) as HTMLElement;
expect(text).toHaveTextContent("Motion Content");
expect(text.className).toContain("animate-motion-content-in-tooltip");
});
});
19 changes: 13 additions & 6 deletions src/components/ui/tooltip/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,17 +99,24 @@ function TooltipContent({
side={side}
sideOffset={sideOffset}
className={cn(
"bg-surface-inverse shadow-float animate-in fade-in-0 zoom-in-95",
"data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95",
"data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2",
"data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",
"z-50 w-fit origin-[--radix-tooltip-content-transform-origin] rounded-notice",
"bg-surface-inverse shadow-float",
// アンカーの側から出る(Small)。文字は箱より少し遅れて出る
// en: Pops in from the anchor side (Small); the text lags slightly behind the box
"animate-motion-pop-in-small data-[state=closed]:animate-motion-pop-out-small",
"data-[side=top]:[--motion-pop-from-y:1] data-[side=bottom]:[--motion-pop-from-y:-1]",
"data-[side=left]:[--motion-pop-from-x:1] data-[side=right]:[--motion-pop-from-x:-1]",
"z-50 w-fit origin-(--radix-tooltip-content-transform-origin) rounded-notice",
"px-2 py-1 character-2-regular-pro text-text-inverse",
className
)}
{...props}
>
{children}
<span
data-slot="tooltip-text"
className="block animate-motion-content-in-tooltip"
>
{children}
</span>
<TooltipPrimitive.Arrow className="bg-surface-inverse fill-surface-inverse shadow-float z-50 size-3 translate-y-[calc(-50%_-_1px)] rotate-45 rounded-xs" />
</TooltipPrimitive.Content>
</TooltipPrimitive.Portal>
Expand Down
Loading