Skip to content

Commit cde89e3

Browse files
committed
Swap from React to Preact
This reduces the size of the JS bundles.
1 parent 4349485 commit cde89e3

29 files changed

+262
-1036
lines changed

site/astro.config.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import { defineConfig } from 'astro/config'
2-
import react from '@astrojs/react'
32
import sitemap from '@astrojs/sitemap'
43
import mdx from '@astrojs/mdx'
54
import compress from 'astro-compress'
65
import { rehypeHeadingIds } from '@astrojs/markdown-remark'
76
import { autolinkHeadingsPlugin } from './src/plugins/rehypeHeadings'
87
import rehypeResponsiveTables from './src/plugins/rehypeResponsiveTable'
98

9+
import preact from '@astrojs/preact';
10+
1011
export default defineConfig({
1112
integrations: [
12-
react(),
1313
sitemap({
1414
filter: (page) =>
1515
!page.endsWith("/component-spec-template/"),
@@ -18,6 +18,7 @@ export default defineConfig({
1818
rehypePlugins: [rehypeHeadingIds, autolinkHeadingsPlugin, rehypeResponsiveTables],
1919
}),
2020
compress(),
21+
preact(),
2122
],
2223
site: 'https://open-ui.org',
2324
prefetch: {
@@ -34,4 +35,4 @@ export default defineConfig({
3435
external: ['svgo'],
3536
},
3637
},
37-
})
38+
})

site/package.json

+4-10
Original file line numberDiff line numberDiff line change
@@ -33,28 +33,22 @@
3333
},
3434
"devDependencies": {
3535
"@astrojs/mdx": "^4.0.8",
36-
"@astrojs/react": "4.2.0",
3736
"@astrojs/sitemap": "3.2.1",
3837
"astro": "5.2.5",
3938
"astro-compress": "^2.3.6",
4039
"eslint": "^8.18.0",
41-
"eslint-plugin-react": "^7.30.0",
4240
"hast-util-to-string": "^2.0.0",
4341
"hastscript": "^7.2.0",
4442
"husky": "^4.2.3",
4543
"lint-staged": "^11.1.2",
4644
"prettier": "^2.0.4",
4745
"prettier-plugin-astro": "^0.5.4",
48-
"react": "^18.2.0",
49-
"react-dom": "^18.2.0",
5046
"rehype-autolink-headings": "^6.1.1"
5147
},
5248
"dependencies": {
53-
"@fortawesome/fontawesome-svg-core": "^6.4.2",
54-
"@fortawesome/free-brands-svg-icons": "^6.4.2",
55-
"@fortawesome/free-solid-svg-icons": "^6.4.2",
56-
"@fortawesome/react-fontawesome": "^0.2.0",
57-
"@nanostores/react": "^0.4.0",
58-
"nanostores": "^0.7.1"
49+
"@astrojs/preact": "^4.0.4",
50+
"@preact/signals": "^2.0.1",
51+
"invokers-polyfill": "^0.4.7",
52+
"preact": "^10.25.4"
5953
}
6054
}

site/src/components/anatomy-components.jsx

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import React from 'react'
21
import './anatomy-component.css'
32

43
export const AnatomyWrapper = ({ children }) => (

site/src/components/anatomy.jsx

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import React from 'react'
21
import './anatomy.css'
32

43
import { anatomiesByComponent } from '../sources'

site/src/components/breadcrumb-anatomy.jsx

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import React from 'react'
21
import { AnatomyWrapper, Host, Slot, Part } from './anatomy-components'
32
import './breadcrumb-anatomy.css'
43

site/src/components/checkbox-anatomy.jsx

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import React from 'react'
21
import { AnatomyWrapper, Host, Part, Slot } from './anatomy-components'
32

43
const CheckboxAnatomy = () => {

site/src/components/combobox-anatomy.jsx

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import React from 'react'
21
import { AnatomyWrapper, Host, Part, Slot } from './anatomy-components'
32

43
const ComboboxAnatomy = () => {

site/src/components/community-links.jsx

+33-11
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,48 @@
1-
import React from 'react'
2-
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
3-
import { faDiscord, faGithub, faXTwitter } from '@fortawesome/free-brands-svg-icons'
41
import './community-links.css'
52

6-
const iconStyle = {
7-
width: '24px',
8-
height: '24px',
9-
}
10-
113
export default function CommunityLinks({ className = '' }) {
124
return (
135
<div className={'community-links ' + className}>
146
<a href="https://github.com/openui/open-ui" title="GitHub" rel="noreferrer noopener">
15-
<FontAwesomeIcon style={iconStyle} icon={faGithub} />
7+
<svg
8+
aria-hidden="true"
9+
style="width: 24px; height: 24px"
10+
xmlns="http://www.w3.org/2000/svg"
11+
viewBox="0 0 496 512"
12+
>
13+
<path
14+
fill="currentColor"
15+
d="M165.9 397.4c0 2-2.3 3.6-5.2 3.6-3.3 .3-5.6-1.3-5.6-3.6 0-2 2.3-3.6 5.2-3.6 3-.3 5.6 1.3 5.6 3.6zm-31.1-4.5c-.7 2 1.3 4.3 4.3 4.9 2.6 1 5.6 0 6.2-2s-1.3-4.3-4.3-5.2c-2.6-.7-5.5 .3-6.2 2.3zm44.2-1.7c-2.9 .7-4.9 2.6-4.6 4.9 .3 2 2.9 3.3 5.9 2.6 2.9-.7 4.9-2.6 4.6-4.6-.3-1.9-3-3.2-5.9-2.9zM244.8 8C106.1 8 0 113.3 0 252c0 110.9 69.8 205.8 169.5 239.2 12.8 2.3 17.3-5.6 17.3-12.1 0-6.2-.3-40.4-.3-61.4 0 0-70 15-84.7-29.8 0 0-11.4-29.1-27.8-36.6 0 0-22.9-15.7 1.6-15.4 0 0 24.9 2 38.6 25.8 21.9 38.6 58.6 27.5 72.9 20.9 2.3-16 8.8-27.1 16-33.7-55.9-6.2-112.3-14.3-112.3-110.5 0-27.5 7.6-41.3 23.6-58.9-2.6-6.5-11.1-33.3 2.6-67.9 20.9-6.5 69 27 69 27 20-5.6 41.5-8.5 62.8-8.5s42.8 2.9 62.8 8.5c0 0 48.1-33.6 69-27 13.7 34.7 5.2 61.4 2.6 67.9 16 17.7 25.8 31.5 25.8 58.9 0 96.5-58.9 104.2-114.8 110.5 9.2 7.9 17 22.9 17 46.4 0 33.7-.3 75.4-.3 83.6 0 6.5 4.6 14.4 17.3 12.1C428.2 457.8 496 362.9 496 252 496 113.3 383.5 8 244.8 8zM97.2 352.9c-1.3 1-1 3.3 .7 5.2 1.6 1.6 3.9 2.3 5.2 1 1.3-1 1-3.3-.7-5.2-1.6-1.6-3.9-2.3-5.2-1zm-10.8-8.1c-.7 1.3 .3 2.9 2.3 3.9 1.6 1 3.6 .7 4.3-.7 .7-1.3-.3-2.9-2.3-3.9-2-.6-3.6-.3-4.3 .7zm32.4 35.6c-1.6 1.3-1 4.3 1.3 6.2 2.3 2.3 5.2 2.6 6.5 1 1.3-1.3 .7-4.3-1.3-6.2-2.2-2.3-5.2-2.6-6.5-1zm-11.4-14.7c-1.6 1-1.6 3.6 0 5.9 1.6 2.3 4.3 3.3 5.6 2.3 1.6-1.3 1.6-3.9 0-6.2-1.4-2.3-4-3.3-5.6-2z"
16+
/>
17+
</svg>
1618
</a>
1719

1820
<a href="https://discord.gg/DEWjhSw" title="Discord" rel="noreferrer noopener">
19-
<FontAwesomeIcon style={iconStyle} icon={faDiscord} />
21+
<svg
22+
aria-hidden="true"
23+
style="width: 24px; height: 24px"
24+
xmlns="http://www.w3.org/2000/svg"
25+
viewBox="0 0 640 512"
26+
>
27+
<path
28+
fill="currentColor"
29+
d="M524.5 69.8a1.5 1.5 0 0 0 -.8-.7A485.1 485.1 0 0 0 404.1 32a1.8 1.8 0 0 0 -1.9 .9 337.5 337.5 0 0 0 -14.9 30.6 447.8 447.8 0 0 0 -134.4 0 309.5 309.5 0 0 0 -15.1-30.6 1.9 1.9 0 0 0 -1.9-.9A483.7 483.7 0 0 0 116.1 69.1a1.7 1.7 0 0 0 -.8 .7C39.1 183.7 18.2 294.7 28.4 404.4a2 2 0 0 0 .8 1.4A487.7 487.7 0 0 0 176 479.9a1.9 1.9 0 0 0 2.1-.7A348.2 348.2 0 0 0 208.1 430.4a1.9 1.9 0 0 0 -1-2.6 321.2 321.2 0 0 1 -45.9-21.9 1.9 1.9 0 0 1 -.2-3.1c3.1-2.3 6.2-4.7 9.1-7.1a1.8 1.8 0 0 1 1.9-.3c96.2 43.9 200.4 43.9 295.5 0a1.8 1.8 0 0 1 1.9 .2c2.9 2.4 6 4.9 9.1 7.2a1.9 1.9 0 0 1 -.2 3.1 301.4 301.4 0 0 1 -45.9 21.8 1.9 1.9 0 0 0 -1 2.6 391.1 391.1 0 0 0 30 48.8 1.9 1.9 0 0 0 2.1 .7A486 486 0 0 0 610.7 405.7a1.9 1.9 0 0 0 .8-1.4C623.7 277.6 590.9 167.5 524.5 69.8zM222.5 337.6c-29 0-52.8-26.6-52.8-59.2S193.1 219.1 222.5 219.1c29.7 0 53.3 26.8 52.8 59.2C275.3 311 251.9 337.6 222.5 337.6zm195.4 0c-29 0-52.8-26.6-52.8-59.2S388.4 219.1 417.9 219.1c29.7 0 53.3 26.8 52.8 59.2C470.7 311 447.5 337.6 417.9 337.6z"
30+
/>
31+
</svg>
2032
</a>
2133

2234
<a href="https://x.com/openuicg" title="X" rel="noreferrer noopener">
23-
<FontAwesomeIcon style={iconStyle} icon={faXTwitter} />
35+
<svg
36+
aria-hidden="true"
37+
style="width: 24px; height: 24px"
38+
xmlns="http://www.w3.org/2000/svg"
39+
viewBox="0 0 512 512"
40+
>
41+
<path
42+
fill="currentColor"
43+
d="M389.2 48h70.6L305.6 224.2 487 464H345L233.7 318.6 106.5 464H35.8L200.7 275.5 26.8 48H172.4L272.9 180.9 389.2 48zM364.4 421.8h39.1L151.1 88h-42L364.4 421.8z"
44+
/>
45+
</svg>
2446
</a>
2547
</div>
2648
)

site/src/components/component-coverage.jsx

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import React from 'react'
21
import { componentsByName, get, uniqBy, groupBy } from '../sources'
32
import './component-coverage.css'
43

site/src/components/component-name-matrix.jsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useState } from 'react'
1+
import { useState } from 'preact/hooks'
22
import { componentOriginalNames, sources, sourcesCount } from '../sources'
33
import './component-name-matrix.css'
44

site/src/components/concept-coverage.jsx

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import React from 'react'
21
import { sourceNames, getSourcesWithComponentConcept } from '../sources'
32
import './concept-coverage.css'
43

site/src/components/concept.jsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useEffect } from 'react'
1+
import { useEffect, useState } from 'preact/hooks'
22
import ConceptCoverage from './concept-coverage'
33
import Specimens from './specimens'
44
import './concept.css'
@@ -11,7 +11,7 @@ export default function Concept({
1111
showDescriptions,
1212
initExpand,
1313
}) {
14-
const [open, toggleOpen] = React.useState(initExpand)
14+
const [open, toggleOpen] = useState(initExpand)
1515

1616
useEffect(() => {
1717
toggleOpen(initExpand)

site/src/components/concepts.jsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import React from 'react'
1+
import { useState } from 'preact/hooks'
22
import { openUIConceptsByComponent } from '../sources'
33
import './concepts.css'
44

55
import Concept from './concept'
66

77
const Concepts = ({ component }) => {
8-
const [showDescriptions, setShowDescriptions] = React.useState(false)
9-
const [collapseAll, toggleCollapseAll] = React.useState(true)
8+
const [showDescriptions, setShowDescriptions] = useState(false)
9+
const [collapseAll, toggleCollapseAll] = useState(true)
1010

1111
const conceptsForComponent = Object.entries(openUIConceptsByComponent[component] || []).sort(
1212
([_a, conceptsA], [_b, conceptsB]) => conceptsA.length - conceptsB.length,

site/src/components/design-systems-list.jsx

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import React from 'react'
21
import { sources } from '../sources'
32
import './design-systems-list.css'
43

site/src/components/file-anatomy.jsx

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import React from 'react'
21
import { AnatomyWrapper, Host, Part, Slot } from './anatomy-components'
32

43
const FileAnatomy = () => {

site/src/components/image.jsx

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import React from 'react'
2-
31
export function Image({ alt = src, src, style }) {
42
return <img alt={alt} srcSet={src + ' 2x'} style={style} />
53
}

site/src/components/missing-images.jsx

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import React from 'react'
21
import './missing-images.css'
32

43
export function MissingImages(props) {

site/src/components/navigation/navigation-container.jsx

+24-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,31 @@
1-
import { useStore } from '@nanostores/react'
2-
import React from 'react'
3-
import { isMenuOpen } from '../../state/menuState'
1+
import { useSignal } from '@preact/signals'
2+
import { useEffect, useRef } from 'preact/hooks'
43

54
function NavigationContainer(props) {
6-
const $isMenuOpen = useStore(isMenuOpen)
5+
const isMenuOpen = useSignal(false)
6+
const navRef = useRef(null)
7+
8+
useEffect(() => {
9+
function handleCommand(e) {
10+
if (e.command === '--toggle-menu') {
11+
isMenuOpen.value = !isMenuOpen.value
12+
e.source.setAttribute('aria-expanded', isMenuOpen.value)
13+
}
14+
}
15+
16+
if (navRef.current) {
17+
navRef.current.addEventListener('command', handleCommand)
18+
}
19+
20+
return () => {
21+
if (navRef.current) {
22+
navRef.current.removeEventListener('command', handleCommand)
23+
}
24+
}
25+
})
726

827
return (
9-
<nav id="site-nav" className={$isMenuOpen ? 'opened' : ''}>
28+
<nav ref={navRef} id="site-nav" className={isMenuOpen.value ? 'opened' : ''}>
1029
{props.children}
1130
</nav>
1231
)

site/src/components/select-anatomy.jsx

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import React from 'react'
21
import { AnatomyWrapper, Host, Part, Slot } from './anatomy-components'
32

43
const SelectAnatomy = () => {

site/src/components/specimens.jsx

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import React from 'react'
21
import { getImagesForComponentConcept } from '../sources'
32
import Image from './image.jsx'
43
import { MissingImages } from './missing-images'

site/src/components/table-anatomy.jsx

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import React from 'react'
21
import './table-anatomy.css'
32

43
const TableAnatomy = () => {

site/src/components/toggle-menu-button.jsx

+15-10
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,29 @@
1-
import { useStore } from '@nanostores/react'
2-
import { isMenuOpen } from '../state/menuState'
3-
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
4-
import { faBars } from '@fortawesome/free-solid-svg-icons'
51
import './toggle-menu-button.css'
2+
import 'invokers-polyfill'
63

74
function ToggleMenuButton() {
8-
const $isMenuOpen = useStore(isMenuOpen)
9-
const onToggleMenu = () => isMenuOpen.set(!$isMenuOpen)
10-
115
return (
126
<button
137
type="button"
148
className="header-menu-btn"
159
aria-label="Toggle menu"
1610
title="Toggle menu"
17-
onClick={onToggleMenu}
18-
aria-expanded={$isMenuOpen ? 'true' : 'false'}
11+
aria-expanded="false"
12+
command="--toggle-menu"
13+
commandfor="site-nav"
1914
aria-controls="site-nav"
2015
>
21-
<FontAwesomeIcon icon={faBars} size="lg" />
16+
<svg
17+
aria-hidden="true"
18+
style="height: 1em; font-size: 1.25em"
19+
xmlns="http://www.w3.org/2000/svg"
20+
viewBox="0 0 448 512"
21+
>
22+
<path
23+
fill="currentColor"
24+
d="M0 96C0 78.3 14.3 64 32 64l384 0c17.7 0 32 14.3 32 32s-14.3 32-32 32L32 128C14.3 128 0 113.7 0 96zM0 256c0-17.7 14.3-32 32-32l384 0c17.7 0 32 14.3 32 32s-14.3 32-32 32L32 288c-17.7 0-32-14.3-32-32zM448 416c0 17.7-14.3 32-32 32L32 448c-17.7 0-32-14.3-32-32s14.3-32 32-32l384 0c17.7 0 32 14.3 32 32z"
25+
/>
26+
</svg>
2227
</button>
2328
)
2429
}

site/src/pages/components/popup.research.explainer.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useEffect } from 'react'
1+
import { useEffect } from 'preact/hooks'
22

33
/**
44
*

site/src/pages/components/select.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useEffect } from 'react'
1+
import { useEffect } from 'preact/hooks'
22

33
function Page() {
44
useEffect(() => {

site/src/pages/components/selectlist.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useEffect } from 'react'
1+
import { useEffect } from 'preact/hooks'
22

33
function Page() {
44
useEffect(() => {

site/src/pages/components/selectmenu.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useEffect } from 'react'
1+
import { useEffect } from 'preact/hooks'
22

33
function Page() {
44
useEffect(() => {

site/src/state/menuState.js

-3
This file was deleted.

site/tsconfig.json

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"extends": "astro/tsconfigs/base",
3+
"compilerOptions": {
4+
"jsx": "react-jsx",
5+
"jsxImportSource": "preact"
6+
}
7+
}

0 commit comments

Comments
 (0)