Skip to content

Commit 070fe96

Browse files
committed
feat: implement the switch in html/css only
1 parent 416f069 commit 070fe96

File tree

5 files changed

+60
-59
lines changed

5 files changed

+60
-59
lines changed

apps/site/components/EOL/EOLReleaseTable/TableBody.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const EOLReleaseTableBody: FC<EOLReleaseTableBodyProps> = ({
2828
<tbody>
2929
{eolReleases.map(release => (
3030
<Fragment key={release.major}>
31-
<tr>
31+
<tr data-lts={!!release.codename}>
3232
<td data-label="Version">
3333
v{release.major} {release.codename ? `(${release.codename})` : ''}
3434
</td>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
@reference "../../../styles/index.css";
2+
3+
.eolTableWrapper {
4+
@apply contents;
5+
}
6+
7+
.eolTableWrapper:has(input[type='checkbox']:checked) tr[data-lts='false'] {
8+
@apply hidden;
9+
}

apps/site/components/EOL/EOLReleaseTable/index.tsx

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
import Switch from '@node-core/ui-components/Common/Switch';
12
import { getTranslations } from 'next-intl/server';
23
import type { FC } from 'react';
34

45
import provideReleaseData from '#site/next-data/providers/releaseData';
56
import provideVulnerabilities from '#site/next-data/providers/vulnerabilities';
67
import { EOL_VERSION_IDENTIFIER } from '#site/next.constants.mjs';
78

9+
import styles from './index.module.css';
810
import EOLReleaseTableBody from './TableBody';
911

1012
const EOLReleaseTable: FC = async () => {
@@ -18,24 +20,27 @@ const EOLReleaseTable: FC = async () => {
1820
const t = await getTranslations();
1921

2022
return (
21-
<table id="tbVulnerabilities">
22-
<thead>
23-
<tr>
24-
<th>
25-
{t('components.eolTable.version')} (
26-
{t('components.eolTable.codename')})
27-
</th>
28-
<th>{t('components.eolTable.lastUpdated')}</th>
29-
<th>{t('components.eolTable.vulnerabilities')}</th>
30-
<th>{t('components.eolTable.details')}</th>
31-
</tr>
32-
</thead>
33-
34-
<EOLReleaseTableBody
35-
eolReleases={eolReleases}
36-
vulnerabilities={vulnerabilities}
37-
/>
38-
</table>
23+
<div className={styles.eolTableWrapper}>
24+
<Switch id="hide-non-lts" label={t('components.eolTable.hideNonLts')} />
25+
<table id="tbVulnerabilities">
26+
<thead>
27+
<tr>
28+
<th>
29+
{t('components.eolTable.version')} (
30+
{t('components.eolTable.codename')})
31+
</th>
32+
<th>{t('components.eolTable.lastUpdated')}</th>
33+
<th>{t('components.eolTable.vulnerabilities')}</th>
34+
<th>{t('components.eolTable.details')}</th>
35+
</tr>
36+
</thead>
37+
38+
<EOLReleaseTableBody
39+
eolReleases={eolReleases}
40+
vulnerabilities={vulnerabilities}
41+
/>
42+
</table>
43+
</div>
3944
);
4045
};
4146

packages/ui-components/src/Common/Switch/index.module.css

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
dark:text-neutral-200;
1515
}
1616

17+
.input {
18+
@apply sr-only;
19+
}
20+
1721
.root {
1822
@apply w-10.5
1923
relative
@@ -23,20 +27,22 @@
2327
items-center
2428
rounded-full
2529
bg-black
26-
focus:outline-none
27-
focus-visible:ring-2
28-
focus-visible:ring-green-500
29-
focus-visible:ring-offset-2
30-
focus-visible:ring-offset-neutral-100
3130
motion-safe:transition-colors
3231
motion-safe:duration-100
3332
motion-safe:ease-out
34-
dark:bg-neutral-700
35-
dark:focus-visible:ring-green-400
36-
dark:focus-visible:ring-offset-neutral-900;
33+
dark:bg-neutral-700;
34+
}
35+
36+
.input:focus-visible + .root {
37+
@apply ring-2
38+
ring-green-500
39+
ring-offset-2
40+
ring-offset-neutral-100
41+
dark:ring-green-400
42+
dark:ring-offset-neutral-900;
3743
}
3844

39-
.root[data-state='checked'] {
45+
.input:checked + .root {
4046
@apply bg-green-600;
4147
}
4248

@@ -53,7 +59,7 @@
5359
motion-safe:ease-out;
5460
}
5561

56-
.thumb[data-state='checked'] {
62+
.input:checked + .root .thumb {
5763
@apply translate-x-5;
5864
}
5965
}

packages/ui-components/src/Common/Switch/index.tsx

Lines changed: 11 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,29 @@
1-
'use client';
2-
3-
import * as SwitchPrimitive from '@radix-ui/react-switch';
41
import classNames from 'classnames';
5-
import { useId } from 'react';
6-
import type { FC, PropsWithChildren } from 'react';
2+
import type { FC, PropsWithChildren, InputHTMLAttributes } from 'react';
73

84
import styles from './index.module.css';
95

10-
type SwitchProps = SwitchPrimitive.SwitchProps & {
6+
type SwitchProps = InputHTMLAttributes<HTMLInputElement> & {
7+
id: string;
118
label?: string;
12-
checked?: boolean;
13-
onCheckedChange?: (checked: boolean) => void;
149
thumbClassName?: string;
1510
};
1611

1712
const Switch: FC<PropsWithChildren<SwitchProps>> = ({
1813
label,
19-
checked,
20-
onCheckedChange,
2114
className,
2215
thumbClassName,
16+
id,
2317
...props
2418
}) => {
25-
const id = useId();
26-
2719
return (
28-
<div className={styles.switch}>
29-
{label && (
30-
<label className={styles.label} htmlFor={id}>
31-
{label}
32-
</label>
33-
)}
34-
<SwitchPrimitive.Root
35-
id={id}
36-
className={classNames(styles.root, className)}
37-
checked={checked}
38-
onCheckedChange={onCheckedChange}
39-
{...props}
40-
>
41-
<SwitchPrimitive.Thumb
42-
className={classNames(styles.thumb, thumbClassName)}
43-
/>
44-
</SwitchPrimitive.Root>
45-
</div>
20+
<label className={styles.switch}>
21+
{label && <span className={styles.label}>{label}</span>}
22+
<input id={id} type="checkbox" className={styles.input} {...props} />
23+
<div className={classNames(styles.root, className)}>
24+
<div className={classNames(styles.thumb, thumbClassName)} />
25+
</div>
26+
</label>
4627
);
4728
};
4829

0 commit comments

Comments
 (0)