Skip to content

Commit 0ce5db8

Browse files
authored
feat: add @primer/styled-react package (#6417)
1 parent 8903f9d commit 0ce5db8

File tree

14 files changed

+425
-11
lines changed

14 files changed

+425
-11
lines changed

.changeset/spotty-coats-post.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@primer/styled-react': minor
3+
---
4+
5+
Create the `@primer/styled-react` package to help with bridging between styled-components and Primer React

package-lock.json

Lines changed: 183 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/styled-react/README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# @primer/styled-react
2+
3+
> A temporary package that bridges the gap between Primer React and styled-components
4+
5+
## Getting started
6+
7+
To install `@primer/styled-react` in your project, you will need to run the following
8+
command using [npm](https://www.npmjs.com/):
9+
10+
```bash
11+
npm install -S @primer/styled-react
12+
```
13+
14+
## Usage
15+
16+
This is a pre-1.0 package designed to interop between Primer and existing
17+
styled-components usage. As a result, expect breaking changes between minor
18+
versions as components will be removed when their `sx` usage goes to zero.
19+
20+
Each component that is imported from `@primer/styled-react` is a wrapper around
21+
the corresponding component in `@primer/react`. The notable difference is that
22+
these components support the `sx` prop and styled system props.
23+
24+
By default, each component is deprecated. The intent is to transition code over
25+
to an alternative styling solution, such as CSS Modules.
26+
27+
## 📖 Documentation
28+
29+
The documentation for `@primer/react` lives at [primer.style](https://primer.style). There, you'll find detailed documentation on getting started, all of the components, our theme, our principles, and more.
30+
31+
## 🙌 Contributing
32+
33+
We love collaborating with folks inside and outside of GitHub and welcome contributions! If you're interested, check out our [contributing docs](contributor-docs/CONTRIBUTING.md) for more info on how to get started.

packages/styled-react/package.json

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
{
2+
"name": "@primer/styled-react",
3+
"version": "0.0.0",
4+
"type": "module",
5+
"exports": {
6+
".": {
7+
"types": "dist/index.d.ts",
8+
"default": "dist/index.js"
9+
},
10+
"./deprecated": {
11+
"types": "dist/deprecated.d.ts",
12+
"default": "dist/deprecated.js"
13+
},
14+
"./experimental": {
15+
"types": "dist/experimental.d.ts",
16+
"default": "dist/experimental.js"
17+
}
18+
},
19+
"files": [
20+
"README.md",
21+
"dist"
22+
],
23+
"scripts": {
24+
"build": "script/build",
25+
"clean": "rimraf dist",
26+
"type-check": "tsc --noEmit"
27+
},
28+
"devDependencies": {
29+
"@babel/preset-typescript": "^7.27.1",
30+
"@primer/react": "^37.29.1",
31+
"@rollup/plugin-babel": "^6.0.4",
32+
"@types/react": "18.3.11",
33+
"@types/react-dom": "18.3.1",
34+
"react": "18.3.1",
35+
"react-dom": "18.3.1",
36+
"rimraf": "^6.0.1",
37+
"rollup": "4.45.1",
38+
"rollup-plugin-typescript2": "^0.36.0",
39+
"styled-components": "5.3.11",
40+
"typescript": "^5.8.2"
41+
},
42+
"peerDependencies": {
43+
"@primer/react": "^37.29.1",
44+
"@types/react": "18.x || 19.x",
45+
"@types/react-dom": "18.x || 19.x",
46+
"@types/react-is": "18.x || 19.x",
47+
"@types/styled-components": "^5.1.11",
48+
"react": "18.x || 19.x",
49+
"react-dom": "18.x || 19.x",
50+
"react-is": "18.x || 19.x",
51+
"styled-components": "5.x"
52+
},
53+
"peerDependenciesMeta": {
54+
"@types/react": {
55+
"optional": true
56+
},
57+
"@types/react-dom": {
58+
"optional": true
59+
},
60+
"@types/react-is": {
61+
"optional": true
62+
},
63+
"@types/styled-components": {
64+
"optional": true
65+
}
66+
}
67+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import babel from '@rollup/plugin-babel'
2+
import {defineConfig} from 'rollup'
3+
import typescript from 'rollup-plugin-typescript2'
4+
import packageJson from './package.json' with {type: 'json'}
5+
6+
const dependencies = [
7+
...Object.keys(packageJson.peerDependencies ?? {}),
8+
...Object.keys(packageJson.dependencies ?? {}),
9+
...Object.keys(packageJson.devDependencies ?? {}),
10+
]
11+
12+
function createPackageRegex(name) {
13+
return new RegExp(`^${name}(/.*)?`)
14+
}
15+
16+
export default defineConfig({
17+
input: ['src/index.ts', 'src/experimental.ts', 'src/deprecated.ts'],
18+
external: dependencies.map(createPackageRegex),
19+
plugins: [
20+
typescript({
21+
tsconfig: 'tsconfig.build.json',
22+
}),
23+
babel({
24+
presets: ['@babel/preset-typescript'],
25+
extensions: ['.ts', '.tsx'],
26+
babelHelpers: 'bundled',
27+
}),
28+
],
29+
output: {
30+
dir: 'dist',
31+
format: 'esm',
32+
},
33+
})

packages/styled-react/script/build

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
3+
npx rollup -c

0 commit comments

Comments
 (0)