Skip to content

Commit 2123ddf

Browse files
committed
Merge branch 'dev' into shadcn-mobile-menu
2 parents a1dfb28 + 31519ca commit 2123ddf

File tree

12 files changed

+198
-51
lines changed

12 files changed

+198
-51
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
"@radix-ui/react-dialog": "^1.1.1",
4040
"@radix-ui/react-navigation-menu": "^1.2.0",
4141
"@radix-ui/react-popover": "^1.1.1",
42+
"@radix-ui/react-radio-group": "^1.2.0",
4243
"@radix-ui/react-slot": "^1.1.0",
4344
"@radix-ui/react-visually-hidden": "^1.1.0",
4445
"@socialgouv/matomo-next": "^1.8.0",
@@ -131,4 +132,4 @@
131132
"jackspeak": "2.1.1",
132133
"sharp": "0.32.6"
133134
}
134-
}
135+
}

src/components/Footer.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import Translation from "@/components/Translation"
99
import { cn } from "@/lib/utils/cn"
1010
import { scrollIntoView } from "@/lib/utils/scrollIntoView"
1111

12-
import { BaseLink } from "../../tailwind/Link"
1312
import { Button } from "../../tailwind/ui/buttons/Button"
13+
import { BaseLink } from "../../tailwind/ui/Link"
1414

1515
import { List, ListItem } from "./ui/list"
1616

src/components/SkipLink.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { useTranslation } from "next-i18next"
22

33
import { MAIN_CONTENT_ID } from "@/lib/constants"
44

5-
import { BaseLink } from "../../tailwind/Link"
5+
import { BaseLink } from "../../tailwind/ui/Link"
66

77
export const SkipLink = () => {
88
const { t } = useTranslation()

tailwind/ui/Checkbox.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ import * as CheckboxPrimitive from "@radix-ui/react-checkbox"
44

55
import { cn } from "@/lib/utils/cn"
66

7+
/**
8+
* Common style classes for the checkbox, radio, and switch controls
9+
*/
10+
export const commonControlClasses =
11+
"size-4 border border-body-medium text-background hover:border-primary-high-contrast hover:bg-body-light focus-visible:outline-offset-4 focus-visible:outline-primary-hover disabled:cursor-not-allowed disabled:border-disabled disabled:bg-disabled aria-[invalid]:border-error aria-[invalid]:bg-error-light data-[state='checked']:not-disabled:border-primary data-[state='checked']:not-disabled:bg-primary data-[state='checked']:hover:not-disabled:bg-primary-hover"
12+
713
export type CheckboxProps = React.ComponentPropsWithoutRef<
814
typeof CheckboxPrimitive.Root
915
>
@@ -14,10 +20,7 @@ const Checkbox = React.forwardRef<
1420
>(({ className, ...props }, ref) => (
1521
<CheckboxPrimitive.Root
1622
ref={ref}
17-
className={cn(
18-
"size-4 rounded-sm border border-body-medium text-background hover:border-primary-high-contrast hover:bg-body-light focus-visible:outline-offset-4 focus-visible:outline-primary-hover disabled:cursor-not-allowed disabled:border-disabled disabled:bg-disabled aria-[invalid]:border-error aria-[invalid]:bg-error-light data-[state='checked']:not-disabled:border-primary data-[state='checked']:not-disabled:bg-primary data-[state='checked']:hover:not-disabled:bg-primary-hover",
19-
className
20-
)}
23+
className={cn(commonControlClasses, "rounded-sm", className)}
2124
{...props}
2225
>
2326
<CheckboxPrimitive.Indicator className="flex items-center justify-center">
File renamed without changes.

tailwind/ui/RadioGroup.tsx

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import * as React from "react"
2+
import { MdCircle } from "react-icons/md"
3+
import * as RadioGroupPrimitive from "@radix-ui/react-radio-group"
4+
5+
import { cn } from "@/lib/utils/cn"
6+
7+
import { commonControlClasses } from "./Checkbox"
8+
9+
const RadioGroup = React.forwardRef<
10+
React.ElementRef<typeof RadioGroupPrimitive.Root>,
11+
React.ComponentPropsWithoutRef<typeof RadioGroupPrimitive.Root>
12+
>(({ className, ...props }, ref) => {
13+
return (
14+
<RadioGroupPrimitive.Root
15+
className={cn("grid gap-2", className)}
16+
{...props}
17+
ref={ref}
18+
/>
19+
)
20+
})
21+
RadioGroup.displayName = RadioGroupPrimitive.Root.displayName
22+
23+
type RadioGroupItemProps = React.ComponentPropsWithoutRef<
24+
typeof RadioGroupPrimitive.Item
25+
>
26+
27+
const RadioGroupItem = React.forwardRef<
28+
React.ElementRef<typeof RadioGroupPrimitive.Item>,
29+
RadioGroupItemProps
30+
>(({ className, ...props }, ref) => {
31+
return (
32+
<RadioGroupPrimitive.Item
33+
ref={ref}
34+
className={cn(commonControlClasses, "rounded-full", className)}
35+
{...props}
36+
>
37+
<RadioGroupPrimitive.Indicator className="flex items-center justify-center">
38+
<MdCircle className="size-2" />
39+
</RadioGroupPrimitive.Indicator>
40+
</RadioGroupPrimitive.Item>
41+
)
42+
})
43+
RadioGroupItem.displayName = RadioGroupPrimitive.Item.displayName
44+
45+
export { RadioGroup, RadioGroupItem, type RadioGroupItemProps }

tailwind/ui/__stories__/Button.stories.tsx

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
import { MdChevronRight, MdExpandMore, MdNightlight } from "react-icons/md"
1+
import { MdChevronRight, MdExpandMore } from "react-icons/md"
22
import type { Meta, StoryObj } from "@storybook/react"
33

4-
import Translation from "@/components/Translation"
5-
64
import { HStack, VStack } from "../../../src/components/ui/flex"
75
import { Button, type ButtonVariantProps } from "../buttons/Button"
8-
import { ButtonLink } from "../buttons/Button"
96

107
const meta = {
118
title: "Atoms / Form / ShadCn Buttons",
@@ -105,25 +102,3 @@ export const MultiLineText: Story = {
105102
</HStack>
106103
),
107104
}
108-
109-
export const OverrideStyles: Story = {
110-
render: () => (
111-
<>
112-
<p>
113-
Show custom styling examples here for visual testing of overrides from
114-
the theme config
115-
</p>
116-
<VStack>
117-
<Button aria-label="toggle" className="px-1.5">
118-
<MdNightlight />
119-
</Button>
120-
<ButtonLink
121-
className="rounded-full px-0 py-0"
122-
linkProps={{ href: "#" }}
123-
>
124-
<Translation id="get-involved" />
125-
</ButtonLink>
126-
</VStack>
127-
</>
128-
),
129-
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import type { Meta, StoryObj } from "@storybook/react/*"
2+
3+
import { ButtonLink as ButtonLinkComponent } from "../buttons/Button"
4+
5+
const meta = {
6+
title: "Atoms / Form / ShadCn Buttons",
7+
component: ButtonLinkComponent,
8+
} satisfies Meta<typeof ButtonLinkComponent>
9+
10+
export default meta
11+
12+
export const ButtonLink: StoryObj<typeof meta> = {
13+
args: {
14+
href: "#",
15+
children: "What is Ethereum?",
16+
},
17+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import type { Meta, StoryObj } from "@storybook/react/*"
2+
3+
import { HStack } from "../../../src/components/ui/flex"
4+
import {
5+
RadioGroup,
6+
RadioGroupItem,
7+
type RadioGroupItemProps,
8+
} from "../RadioGroup"
9+
10+
const meta = {
11+
title: "Atoms / Form / ShadCN Radio",
12+
component: RadioGroup,
13+
} satisfies Meta<typeof RadioGroup>
14+
15+
export default meta
16+
17+
const DEFAULT_CHECKED = "checked"
18+
19+
const radioSet: Array<RadioGroupItemProps & { label: string }> = [
20+
{
21+
id: "default",
22+
value: "default",
23+
label: "default",
24+
},
25+
{
26+
id: DEFAULT_CHECKED,
27+
value: DEFAULT_CHECKED,
28+
label: DEFAULT_CHECKED,
29+
},
30+
{
31+
id: "disabled",
32+
value: "disabled",
33+
disabled: true,
34+
label: "disabled",
35+
},
36+
{
37+
id: "disabled-checked",
38+
value: "disabled-checked",
39+
disabled: true,
40+
checked: true,
41+
label: "disabled-checked",
42+
},
43+
{
44+
id: "invalid",
45+
value: "invalid",
46+
"aria-invalid": true,
47+
label: "invalid",
48+
},
49+
]
50+
51+
export const Radio: StoryObj<typeof meta> = {
52+
args: {
53+
defaultValue: DEFAULT_CHECKED,
54+
className: "gap-4",
55+
},
56+
render: (args) => (
57+
<RadioGroup {...args}>
58+
{radioSet.map((radio) => (
59+
<HStack key={radio.id} asChild>
60+
<label>
61+
<RadioGroupItem {...radio} />
62+
{radio.label}
63+
</label>
64+
</HStack>
65+
))}
66+
</RadioGroup>
67+
),
68+
}

tailwind/ui/buttons/Button.tsx

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@ import * as React from "react"
22
import { cva, type VariantProps } from "class-variance-authority"
33
import { Slot } from "@radix-ui/react-slot"
44

5-
import { BaseLink, type LinkProps } from "@/components/Link"
6-
75
import { cn } from "@/lib/utils/cn"
86
import { type MatomoEventOptions, trackCustomEvent } from "@/lib/utils/matomo"
97
import { scrollIntoView } from "@/lib/utils/scrollIntoView"
108

9+
import { BaseLink, type LinkProps } from "../Link"
10+
1111
const buttonVariants = cva(
1212
"pointer inline-flex gap-2 items-center justify-center rounded border border-solid border-current text-primary transition focus-visible:outline focus-visible:outline-4 focus-visible:outline-primary-hover focus-visible:-outline-offset-1 disabled:text-disabled disabled:pointer-events-none hover:text-primary-hover [&[data-secondary='true']]:text-body [&>svg]:flex-shrink-0",
1313
{
1414
variants: {
1515
variant: {
1616
solid:
17-
"!text-background bg-primary border-transparent disabled:bg-disabled disabled:text-background hover:text-background hover:bg-primary-hover hover:shadow-button-hover active:shadow-none",
17+
"text-background bg-primary border-transparent disabled:bg-disabled disabled:text-background hover:text-background hover:bg-primary-hover hover:shadow-button-hover active:shadow-none",
1818
outline: "hover:shadow-button-hover active:shadow-none",
1919
ghost: "border-transparent",
2020
link: "border-transparent font-bold underline py-0 px-1 active:text-primary",
@@ -106,29 +106,22 @@ const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
106106
)
107107
Button.displayName = "Button"
108108

109-
type ButtonLinkProps = ButtonProps & {
110-
linkProps: LinkProps
109+
type ButtonLinkProps = Omit<LinkProps, "onClick"> & {
110+
buttonProps?: ButtonProps
111111
customEventOptions?: MatomoEventOptions
112112
}
113113

114114
const ButtonLink = React.forwardRef<HTMLAnchorElement, ButtonLinkProps>(
115-
({ linkProps, customEventOptions, children, ...buttonProps }, ref) => {
115+
({ buttonProps, customEventOptions, children, ...linkProps }, ref) => {
116116
const handleClick = () => {
117117
customEventOptions && trackCustomEvent(customEventOptions)
118118
}
119119
return (
120120
<Button asChild {...buttonProps}>
121121
<BaseLink
122122
ref={ref}
123-
activeStyle={{}}
124-
// TODO: Redress this override when migrating the link component
125-
color={
126-
buttonProps.variant === "solid" ? "background.base" : undefined
127-
}
128-
textDecor="none"
129-
_hover={{
130-
textDecor: "none",
131-
}}
123+
className="no-underline hover:no-underline"
124+
activeClassName=""
132125
{...linkProps}
133126
onClick={handleClick}
134127
>

0 commit comments

Comments
 (0)