@ndla/preset-panda 0.0.52 → 0.0.54
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +148 -0
- package/es/globalCss.js +1 -1
- package/lib/globalCss.js +1 -1
- package/package.json +4 -4
package/README.md
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
# @ndla/preset-panda
|
|
2
|
+
|
|
3
|
+
The styling solution used across all NDLA solutions, powered by and built upon [PandaCSS](https://pandacss.com)
|
|
4
|
+
|
|
5
|
+
## What this package is
|
|
6
|
+
|
|
7
|
+
PandaCSS is a compile-time styling solution powered by PostCSS. At its core it is framework-agnostic, but it also provides thin wrappers for popular JavaScript frameworks. We use the React wrapper. This package exports a preset for PandaCSS, allowing for developers aligned with NDLA to create components using a shared design language. Tokens are exported as plain css variables, and as a Panda preset.
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
yarn add -D @ndla/preset-panda @pandacss/dev postcss
|
|
13
|
+
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Usage
|
|
17
|
+
|
|
18
|
+
This package can be consumed through panda or through plain css. Either way, add this to your css file.
|
|
19
|
+
|
|
20
|
+
```css
|
|
21
|
+
@layer reset, base, tokens, recipes, utilities;
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
### With Panda
|
|
25
|
+
|
|
26
|
+
Setup panda as you normally would, and add the NDLA preset.
|
|
27
|
+
|
|
28
|
+
```tsx
|
|
29
|
+
import preset from "@ndla/preset-panda";
|
|
30
|
+
export default defineConfig({
|
|
31
|
+
presets: [preset],
|
|
32
|
+
});
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### With plain css
|
|
36
|
+
|
|
37
|
+
```css
|
|
38
|
+
/* Probably need a css reset here as well */
|
|
39
|
+
@import "@ndla/preset-panda/dist/styles.css";
|
|
40
|
+
@import "@ndla/primitives/dist/styles.css";
|
|
41
|
+
@import "@ndla/icons/dist/styles.css";
|
|
42
|
+
@import "@ndla/ui/dist/styles.css";
|
|
43
|
+
@import "@ndla/safelink/dist/styles.css";
|
|
44
|
+
|
|
45
|
+
@layer reset, base, tokens, recipes, utilities;
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Plugin for forwarding css prop
|
|
49
|
+
|
|
50
|
+
This package also provides a special plugin that alters the styled system that panda exposes. You can read more about the behavioral changes it introduces [here](./src/plugins/README.md) If you use `@ndla/styled-system`, it is already enabled by default. If you only want to use the plugin, it can be added to any panda configuration by adding it to your plugins.
|
|
51
|
+
|
|
52
|
+
```tsx
|
|
53
|
+
import { forwardCssPropPlugin } from "@ndla/preset-panda";
|
|
54
|
+
export default defineConfig({
|
|
55
|
+
plugins: [forwardCssPropPlugin],
|
|
56
|
+
});
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Guidelines
|
|
60
|
+
|
|
61
|
+
We strive to keep this package as lean as possible, as most other NDLA packages relies upon it, either directly or indirectly. As such, try to keep the `globalCss.ts` file as lean as possible. It is currently reserved for the following scenarios:
|
|
62
|
+
|
|
63
|
+
- Truly global css
|
|
64
|
+
- Resets
|
|
65
|
+
- Global font styling
|
|
66
|
+
- Body styling
|
|
67
|
+
- Extremely large pieces of css
|
|
68
|
+
- Article styling
|
|
69
|
+
- Code block styling (for now).
|
|
70
|
+
|
|
71
|
+
### Semantic tokens
|
|
72
|
+
|
|
73
|
+
Always prefer using semantic tokens wherever possible. Values defined in [colors.ts](./src/colors.ts) and [spacing.ts](./src/spacing.ts) should only be used if absolutely necessary. If the current semantic tokens do not fit your needs, let us know.
|
|
74
|
+
|
|
75
|
+
### Style properties
|
|
76
|
+
|
|
77
|
+
Prefer properties with proper completion and type safety.
|
|
78
|
+
|
|
79
|
+
```tsx
|
|
80
|
+
const bad = css({
|
|
81
|
+
border: "1px solid token(colors.stroke.default)",
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
const good = css({
|
|
85
|
+
border: "1px solid",
|
|
86
|
+
borderColor: "stroke.default",
|
|
87
|
+
});
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
Prefer style properties that are already used throughout the code base, and that can be easily overridden.
|
|
91
|
+
|
|
92
|
+
```tsx
|
|
93
|
+
// Can only be overridden with backgroundColor
|
|
94
|
+
const bad = css({
|
|
95
|
+
backgroundColor: "surface.default",
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
// Can be overridden with both `background` and backgroundColor
|
|
99
|
+
const good = css({
|
|
100
|
+
background: "surface.default",
|
|
101
|
+
});
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
There's a couple of exceptions to this rule, mostly to do with padding and margins. Read source code to get a grasp of how we use those properties :)
|
|
105
|
+
|
|
106
|
+
## Styling Justifications
|
|
107
|
+
|
|
108
|
+
### Shorthand vs longhand properties
|
|
109
|
+
|
|
110
|
+
We prefer using longhand properties wherever possible, and our code generation reflects this. We landed on using longhand properties to lower the cost of entry into the panda ecosystem. Diverging from default css is already a big ask for new developers. By maintaining the likeness with regular css (naming-wise), we hope to encourage developers to write css as they normally would, just camel-cased instead of kebab-cased :)
|
|
111
|
+
|
|
112
|
+
### Styling props
|
|
113
|
+
|
|
114
|
+
PandaCSS offers three styling options when using a framework wrapper: the `css` prop, a `styled-system` like approach, and simple class names. We landed on the `css` approach. Instead of explaining why we landed on this, let's instead explain why we avoid the `styled-system` approach
|
|
115
|
+
|
|
116
|
+
#### Vendor lock-in
|
|
117
|
+
|
|
118
|
+
The biggest disadvantage to using a styled-system approach is that a full rewrite becomes less feasible the more you invest into the Panda ecosystem. Let's compare the two approaches.
|
|
119
|
+
|
|
120
|
+
##### styled-system
|
|
121
|
+
|
|
122
|
+
```tsx
|
|
123
|
+
return <Box display="flex" gap="xsmall" alignItems="center" justifyContent="center" />;
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
##### Minimal (styled somewhere else)
|
|
127
|
+
|
|
128
|
+
```tsx
|
|
129
|
+
return <ListContainer />;
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
The latter example is much more independent from the actual styling solution, allowing for 1:1 rewrites without having to mess with the file history. Furthermore, we believe the latter to be more readable. See complex tailwind components for more horror stories.
|
|
133
|
+
|
|
134
|
+
#### Performance
|
|
135
|
+
|
|
136
|
+
The styled-system approach is extremely flexible, but also comes at a cost. According to [benchmarks](https://github.com/chakra-ui/panda/discussions/2604), that cost is about a 30% drop in performance. We did not want to compromise on that!
|
|
137
|
+
|
|
138
|
+
### Strict property values
|
|
139
|
+
|
|
140
|
+
This is a no-brainer. We want type safety wherever possible.
|
|
141
|
+
|
|
142
|
+
### Why not strictTokens?
|
|
143
|
+
|
|
144
|
+
Turning on strictTokens would allow us to enforce our design system to a much greater extent. In a nutshell, this option only allows tokens that are defined explicitly in `@ndla/preset-panda`. We felt this to be too restrictive. Defining every single css value we use is simply too much, and the escape hatch from this breaks autocomplete entirely.
|
|
145
|
+
|
|
146
|
+
### Preflight position
|
|
147
|
+
|
|
148
|
+
A preflight is more or less a css reset: A small set of css rules that evens out some styling considerations different browsers have decided to have as their defaults. We've chosen to only turn this on where packages are consumed, namely ndla-frontend and editorial-frontend. Enabling it in a package would force all consumers to use our styling reset. Furthermore, it could generate css that neither us nor the consumer actually needs. This is open to change, however. After all, we assume that our reset (or a similar reset) is used.
|
package/es/globalCss.js
CHANGED
|
@@ -181,7 +181,7 @@ export const globalCss = defineGlobalStyles({
|
|
|
181
181
|
"& :nth-last-child(1 of .linenumber)": {
|
|
182
182
|
paddingBlockEnd: "xsmall"
|
|
183
183
|
},
|
|
184
|
-
// The remaining css is copied from the coy theme in prismjs. A lot of css is omitted due to styling clashes
|
|
184
|
+
// The remaining css is copied from the coy theme in prismjs. A lot of css is omitted due to styling clashes. TODO: Consider moving this
|
|
185
185
|
"& .token.comment, .token.block-comment, .token.prolog, .token.doctype, .token.cdata": {
|
|
186
186
|
color: "#7d8b99"
|
|
187
187
|
},
|
package/lib/globalCss.js
CHANGED
|
@@ -187,7 +187,7 @@ const globalCss = exports.globalCss = (0, _dev.defineGlobalStyles)({
|
|
|
187
187
|
"& :nth-last-child(1 of .linenumber)": {
|
|
188
188
|
paddingBlockEnd: "xsmall"
|
|
189
189
|
},
|
|
190
|
-
// The remaining css is copied from the coy theme in prismjs. A lot of css is omitted due to styling clashes
|
|
190
|
+
// The remaining css is copied from the coy theme in prismjs. A lot of css is omitted due to styling clashes. TODO: Consider moving this
|
|
191
191
|
"& .token.comment, .token.block-comment, .token.prolog, .token.doctype, .token.cdata": {
|
|
192
192
|
color: "#7d8b99"
|
|
193
193
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ndla/preset-panda",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.54",
|
|
4
4
|
"description": "Panda preset for NDLA.",
|
|
5
5
|
"license": "GPL-3.0",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -31,11 +31,11 @@
|
|
|
31
31
|
"lib"
|
|
32
32
|
],
|
|
33
33
|
"devDependencies": {
|
|
34
|
-
"@ndla/core": "^
|
|
35
|
-
"@pandacss/dev": "^0.53.
|
|
34
|
+
"@ndla/core": "^6.0.0-alpha.0",
|
|
35
|
+
"@pandacss/dev": "^0.53.6"
|
|
36
36
|
},
|
|
37
37
|
"publishConfig": {
|
|
38
38
|
"access": "public"
|
|
39
39
|
},
|
|
40
|
-
"gitHead": "
|
|
40
|
+
"gitHead": "168853a36b0654ff01db41b8b78e81b1afb66768"
|
|
41
41
|
}
|