Skip to content

Commit 8ada765

Browse files
Tabs.Link: fix selected state on=darkBackground
1 parent 678544b commit 8ada765

File tree

3 files changed

+67
-48
lines changed

3 files changed

+67
-48
lines changed

.changeset/cold-wolves-play.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@cambly/syntax-core": minor
3+
---
4+
5+
Tabs.Link: fix selected state on=darkBackground

packages/syntax-core/src/Tabs/TabLink.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ const TabLink = forwardRef<HTMLAnchorElement, TabLinkProps>(
5757
[styles.unselectedTab]: !selected,
5858
[styles.selectedTabOnLightBackground]:
5959
selected && on === "lightBackground",
60-
[styles.selectedTabDarkBackground]:
60+
[styles.selectedTabOnDarkBackground]:
6161
selected && on === "darkBackground",
6262
})}
6363
style={{

packages/syntax-core/src/Tabs/Tabs.stories.tsx

Lines changed: 61 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { type StoryObj, type Meta } from "@storybook/react";
33
import Tabs from "./Tabs";
44
import Badge from "../Badge/Badge";
55
import Box from "../Box/Box";
6+
import SelectList from "../SelectList/SelectList";
67

78
export default {
89
title: "Components/Tabs",
@@ -29,7 +30,7 @@ export default {
2930
const TabsButtonInteractive = ({
3031
on,
3132
}: {
32-
on: "lightBackground" | "darkBackground";
33+
on?: "lightBackground" | "darkBackground";
3334
}) => {
3435
const [selected, setSelected] = useState<
3536
"Achievements" | "History" | "Quizzes" | "Levels" | "Tabatha" | "Tabathy"
@@ -81,74 +82,83 @@ const TabsButtonInteractive = ({
8182
);
8283
};
8384

84-
const TabsLinkInteractive = ({
85-
on,
86-
}: {
87-
on: "lightBackground" | "darkBackground";
88-
}) => {
85+
const TabsLinkInteractive = () => {
8986
const [selected, setSelected] = useState<"Tabrell" | "Tabara" | "Tabson">(
9087
"Tabrell",
9188
);
92-
93-
return (
94-
<Tabs accessibilityLabel="My custom tabs" on={on}>
95-
<Tabs.Link
96-
href="https://cambly-syntax.vercel.app/?path=/docs/components-tabs--docs"
97-
text="Tabrell"
98-
onClick={() => setSelected("Tabrell")}
99-
selected={selected === "Tabrell"}
100-
on={on}
101-
/>
102-
<Tabs.Link
103-
href="https://cambly-syntax.vercel.app/?path=/docs/components-tabs--docs"
104-
text="Tabara"
105-
onClick={() => setSelected("Tabara")}
106-
selected={selected === "Tabara"}
107-
on={on}
108-
/>
109-
<Tabs.Link
110-
href="https://cambly-syntax.vercel.app/?path=/docs/components-tabs--docs"
111-
text="Tabson"
112-
onClick={() => setSelected("Tabson")}
113-
selected={selected === "Tabson"}
114-
on={on}
115-
/>
116-
</Tabs>
89+
const [on, setOn] = useState<"lightBackground" | "darkBackground">(
90+
"lightBackground",
11791
);
118-
};
11992

120-
export const Default: StoryObj<
121-
ComponentProps<typeof Tabs> & { on: "lightBackground" | "darkBackground" }
122-
> = {
123-
args: { accessibilityLabel: "My custom tabs" },
124-
render: (args) => {
125-
return (
93+
return (
94+
<Box display="flex" direction="column" gap={2}>
95+
<SelectList
96+
id="on"
97+
label="Background"
98+
selectedValue={on}
99+
onChange={(event) =>
100+
setOn(
101+
event.target.value === "lightBackground"
102+
? "lightBackground"
103+
: "darkBackground",
104+
)
105+
}
106+
>
107+
<SelectList.Option
108+
value="lightBackground"
109+
label="Light"
110+
></SelectList.Option>
111+
<SelectList.Option
112+
value="darkBackground"
113+
label="Dark"
114+
></SelectList.Option>
115+
</SelectList>
126116
<Box
127117
padding={2}
128-
width="fit-content"
129118
dangerouslySetInlineStyle={{
130119
__style: {
131120
backgroundImage:
132-
args.on === "darkBackground"
121+
on === "darkBackground"
133122
? "linear-gradient(0deg, #000, #555 )"
134123
: null,
135124
},
136125
}}
137126
>
138-
<TabsButtonInteractive {...args} />
127+
<Tabs accessibilityLabel="My custom tabs" on={on}>
128+
<Tabs.Link
129+
href="https://cambly-syntax.vercel.app/?path=/docs/components-tabs--docs"
130+
text="Tabrell"
131+
onClick={() => setSelected("Tabrell")}
132+
selected={selected === "Tabrell"}
133+
on={on}
134+
/>
135+
<Tabs.Link
136+
href="https://cambly-syntax.vercel.app/?path=/docs/components-tabs--docs"
137+
text="Tabara"
138+
onClick={() => setSelected("Tabara")}
139+
selected={selected === "Tabara"}
140+
on={on}
141+
/>
142+
<Tabs.Link
143+
href="https://cambly-syntax.vercel.app/?path=/docs/components-tabs--docs"
144+
text="Tabson"
145+
onClick={() => setSelected("Tabson")}
146+
selected={selected === "Tabson"}
147+
on={on}
148+
/>
149+
</Tabs>
139150
</Box>
140-
);
141-
},
151+
</Box>
152+
);
142153
};
143154

144-
export const Link: StoryObj<
145-
ComponentProps<typeof Tabs> & { on: "lightBackground" | "darkBackground" }
146-
> = {
155+
export const Default: StoryObj<ComponentProps<typeof Tabs>> = {
147156
args: { accessibilityLabel: "My custom tabs" },
148157
render: (args) => {
149158
return (
150159
<Box
151160
padding={2}
161+
width="fit-content"
152162
dangerouslySetInlineStyle={{
153163
__style: {
154164
backgroundImage:
@@ -158,8 +168,12 @@ export const Link: StoryObj<
158168
},
159169
}}
160170
>
161-
<TabsLinkInteractive {...args} />
171+
<TabsButtonInteractive {...args} />
162172
</Box>
163173
);
164174
},
165175
};
176+
177+
export const Link: StoryObj<ComponentProps<typeof Tabs>> = {
178+
render: () => <TabsLinkInteractive />,
179+
};

0 commit comments

Comments
 (0)