@obosbbl/grunnmuren-tailwind 0.1.0 → 0.3.0

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.
Files changed (3) hide show
  1. package/README.md +30 -1
  2. package/package.json +1 -1
  3. package/tailwind-base.cjs +246 -206
package/README.md CHANGED
@@ -12,8 +12,37 @@ npm install -D @obosbbl/grunnmuren-tailwind tailwindcss
12
12
 
13
13
  ```js
14
14
  // tailwind.config.js
15
+
16
+ // Regular usage
15
17
  module.exports = {
16
18
  presets: [require('@obosbbl/grunnmuren-tailwind')],
17
- // ...
19
+ content: [
20
+ // If using this together with Grunnmuren's React components
21
+ './node_modules/@obosbbl/grunnmuren-react/dist/**/*.js',
22
+ // Add your own content sources as needed, eg:
23
+ './src/components/**/*.{ts,tsx}',
24
+ ],
25
+ };
26
+
27
+ // Usage with options
28
+ module.exports = {
29
+ presets: [require('@obosbbl/grunnmuren-tailwind')({ useLegacyFont: true, fontBasePath: '/mypath/myfonts' }),
30
+ // content: [ ... ]
18
31
  };
19
32
  ```
33
+
34
+ ### Fonts
35
+
36
+ The preset includes font declarations.
37
+ You'll have to setup your app so it serves the necessary [font files](../react/public/fonts/).
38
+ By default the fonts should be under `/fonts/` but you can override this with the config option `fontBasePath`.
39
+ See the [preset implementation](./tailwind-base.cjs).
40
+
41
+ ## Options
42
+
43
+ The preset supports the following options:
44
+
45
+ | Name | Default value | Description |
46
+ | ------------- | ------------- | -------------------------------------------- |
47
+ | useLegacyFont | `false` | Whether to use the fonts from the old design |
48
+ | fontBasePath | `/fonts` | Path to where the fonts are hosted |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@obosbbl/grunnmuren-tailwind",
3
- "version": "0.1.0",
3
+ "version": "0.3.0",
4
4
  "description": "Grunnmuren Tailwind preset",
5
5
  "license": "MIT",
6
6
  "type": "commonjs",
package/tailwind-base.cjs CHANGED
@@ -1,26 +1,49 @@
1
1
  const plugin = require('tailwindcss/plugin');
2
2
 
3
3
  // naively assume all fonts are hosted at the following paths at the root of the app
4
- const fonts = [
4
+ const gorditaFonts = [
5
5
  {
6
6
  fontWeight: 400,
7
7
  fontStyle: 'normal',
8
- url: '/fonts/gorditaregular-webfont.woff2',
8
+ url: '/gorditaregular-webfont.woff2',
9
9
  },
10
10
  {
11
11
  fontWeight: 400,
12
12
  fontStyle: 'italic',
13
- url: '/fonts/gorditaregularitalic-webfont.woff2',
13
+ url: '/gorditaregularitalic-webfont.woff2',
14
14
  },
15
15
  {
16
16
  fontWeight: 500,
17
17
  fontStyle: 'normal',
18
- url: '/fonts/gorditamedium-webfont.woff2',
18
+ url: '/gorditamedium-webfont.woff2',
19
19
  },
20
20
  {
21
21
  fontWeight: 700,
22
22
  fontStyle: 'normal',
23
- url: '/fonts/gorditabold-webfont.woff2',
23
+ url: '/gorditabold-webfont.woff2',
24
+ },
25
+ ];
26
+
27
+ const obosFonts = [
28
+ {
29
+ fontWeight: 400,
30
+ fontStyle: 'normal',
31
+ url: '/OBOSText-Regular.woff2',
32
+ },
33
+ {
34
+ fontWeight: 400,
35
+ fontStyle: 'italic',
36
+ url: '/OBOSText-Italic.woff2',
37
+ },
38
+ {
39
+ fontWeight: 500,
40
+ fontStyle: 'normal',
41
+ url: '/OBOSText-Medium.woff2',
42
+ },
43
+ {
44
+ fontWeight: 700,
45
+ fontStyle: 'normal',
46
+ url: '/OBOSText-Bold.woff2',
24
47
  },
25
48
  ];
26
49
 
@@ -29,7 +52,7 @@ const button = plugin(function ({ addComponents }) {
29
52
  // ideally this would be solved by just darkening the button background,
30
53
  // but that doesn't really work since some of the button variations have transparent backgrounds
31
54
  addComponents({
32
- '.gm-button': {
55
+ '.button': {
33
56
  '&::after': {
34
57
  content: '""',
35
58
  position: 'absolute',
@@ -52,7 +75,7 @@ const button = plugin(function ({ addComponents }) {
52
75
 
53
76
  const checkbox = plugin(function ({ addComponents }) {
54
77
  addComponents({
55
- '.gm-checkbox': {
78
+ '.checkbox': {
56
79
  '&::before': {
57
80
  content: '""',
58
81
  width: '0.65em',
@@ -92,16 +115,16 @@ const headings = plugin(function ({ addBase, addComponents }) {
92
115
  });
93
116
 
94
117
  addComponents({
95
- '.gm-h1': {
118
+ '.h1': {
96
119
  [h1]: {},
97
120
  },
98
- '.gm-h2': {
121
+ '.h2': {
99
122
  [h2]: {},
100
123
  },
101
- '.gm-h3': {
124
+ '.h3': {
102
125
  [h3]: {},
103
126
  },
104
- '.gm-h4': {
127
+ '.h4': {
105
128
  [h4]: {},
106
129
  },
107
130
  });
@@ -109,230 +132,247 @@ const headings = plugin(function ({ addBase, addComponents }) {
109
132
 
110
133
  const snackbar = plugin(function ({ addComponents, theme }) {
111
134
  addComponents({
112
- '.gm-snackbar': {
135
+ '.snackbar': {
113
136
  'grid-template-columns': 'min-content auto',
114
137
  'grid-template-areas': '"icon header" ". content" "actions actions"',
115
138
  },
116
139
  [`@media(min-width: ${theme('screens.md')})`]: {
117
- '.gm-snackbar': {
140
+ '.snackbar': {
118
141
  'grid-template-columns': 'min-content auto auto',
119
142
  'grid-template-areas': '"icon header actions" ". content content"',
120
143
  },
121
144
  },
122
- '.gm-snackbar-icon': {
145
+ '.snackbar-icon': {
123
146
  'grid-area': 'icon',
124
147
  },
125
- '.gm-snackbar-header': {
148
+ '.snackbar-header': {
126
149
  'grid-area': 'header',
127
150
  },
128
- '.gm-snackbar-content': {
151
+ '.snackbar-content': {
129
152
  'grid-area': 'content',
130
153
  },
131
- '.gm-snackbar-actions': {
154
+ '.snackbar-actions': {
132
155
  'grid-area': 'actions',
133
156
  },
134
157
  });
135
158
  });
136
159
 
137
- module.exports = {
138
- plugins: [
139
- // TODO: Remove the aspect ratio plugin when Safari 14 usage is low enough
140
- require('@tailwindcss/aspect-ratio'),
141
- require('@tailwindcss/typography'),
142
- button,
143
- headings,
144
- checkbox,
145
- snackbar,
146
- plugin(function ({ addBase, addUtilities, addComponents }) {
147
- addBase({
148
- html: {
149
- '@apply text-black antialiased font-normal': {},
150
- },
151
- b: {
152
- fontWeight: 500,
153
- },
154
- strong: {
155
- fontWeight: 500,
156
- },
157
- a: {
158
- '@apply underline': {},
159
- },
160
- '::selection': { '@apply bg-green-light text-black': {} },
161
- });
162
- addComponents({
163
- '.container': {
164
- width: '100%',
165
- paddingLeft: '1rem',
166
- paddingRight: '1rem',
167
- marginLeft: 'auto',
168
- marginRight: 'auto',
169
- maxWidth: '90rem',
170
- },
171
- '.container-prose': {
172
- width: '100%',
173
- paddingLeft: '1rem',
174
- paddingRight: '1rem',
175
- marginLeft: 'auto',
176
- marginRight: 'auto',
177
- maxWidth: '37rem',
178
- },
179
- // that thin blue line at the top
180
- '.gm-topline::before': {
181
- display: 'block',
182
- width: '100%',
183
- height: '5px',
184
- content: '""',
185
- position: 'fixed',
186
- left: '0',
187
- top: '0',
188
- right: '0',
189
- // FIXME: Not sure why this doesn't work
190
- //backgroundColor: theme('colors.blue'),
191
- backgroundColor: '#0047BA',
192
- zIndex: '100',
193
- },
194
- /**
195
- * Round the corners of our main content.
196
- * Protip: Use this together with navbar, footer and `bg-blue` class on the body.
197
- */
198
- '.gm-pagemain': {
199
- backgroundColor: '#fff',
200
- borderRadius: '2rem',
201
- overflow: 'hidden',
202
- },
203
- });
204
- addUtilities({
205
- // imitates a bold font, but doesn't cause layout due to element width change like with font-weight
206
- // Note that this CSS isn't standardized, but it works in Fx, Chrome, Safari and Edge
207
- '.fake-font-bold': {
208
- '-webkit-text-stroke': '1px',
209
- },
210
- });
211
- }),
212
- plugin(function ({ addBase }) {
213
- addBase(
214
- fonts.map((font) => ({
215
- '@font-face': {
216
- fontFamily: 'Gordita',
217
- fontWeight: font.fontWeight,
218
- fontStyle: font.fontStyle,
219
- src: `url('${font.url}') format('woff2')`,
220
- fontDisplay: 'swap',
160
+ module.exports = (opts = { useLegacyFont: false, fontBasePath: '/fonts' }) => {
161
+ let fontFamily = 'OBOSFont';
162
+ let fonts = obosFonts;
163
+ if (opts.useLegacyFont) {
164
+ fontFamily = 'Gordita';
165
+ fonts = gorditaFonts;
166
+ }
167
+
168
+ return {
169
+ plugins: [
170
+ // TODO: Remove the aspect ratio plugin when Safari 14 usage is low enough
171
+ require('@tailwindcss/aspect-ratio'),
172
+ require('@tailwindcss/typography'),
173
+ button,
174
+ headings,
175
+ checkbox,
176
+ snackbar,
177
+ plugin(function ({ addBase, addUtilities, addComponents, theme }) {
178
+ addBase({
179
+ html: {
180
+ '@apply text-black antialiased font-normal': {},
221
181
  },
222
- })),
223
- );
224
- }),
225
- ],
226
- corePlugins: {
227
- container: false,
228
- },
229
- theme: {
230
- fontSize: {
231
- sm: '0.875rem',
232
- base: '1rem',
233
- lg: '1.125rem', // 18px
234
- xl: '1.25rem', // 20px
235
- '2xl': '1.5rem', // 24px
236
- '3xl': '1.875rem', // 28px
237
- '4xl': '2rem', // 32px
238
- '5xl': '2.5rem', // 40px
182
+ b: {
183
+ fontWeight: 500,
184
+ },
185
+ strong: {
186
+ fontWeight: 500,
187
+ },
188
+ a: {
189
+ '@apply underline': {},
190
+ },
191
+ '::selection': { '@apply bg-green-light text-black': {} },
192
+ // Remove the disclosure triangle in Safari if apply the `list-none` utility to the summary element
193
+ 'summary.list-none::-webkit-details-marker': {
194
+ display: 'none',
195
+ },
196
+ });
197
+ addComponents({
198
+ '.container': {
199
+ width: '100%',
200
+ paddingLeft: '1rem',
201
+ paddingRight: '1rem',
202
+ marginLeft: 'auto',
203
+ marginRight: 'auto',
204
+ maxWidth: '90rem',
205
+ },
206
+ '.container-prose': {
207
+ width: '100%',
208
+ paddingLeft: '1rem',
209
+ paddingRight: '1rem',
210
+ marginLeft: 'auto',
211
+ marginRight: 'auto',
212
+ maxWidth: '37rem',
213
+ },
214
+ // that thin blue line at the top
215
+ '.topline::before': {
216
+ display: 'block',
217
+ width: '100%',
218
+ height: '5px',
219
+ content: '""',
220
+ position: 'fixed',
221
+ left: '0',
222
+ top: '0',
223
+ right: '0',
224
+ backgroundColor: theme('colors.blue.DEFAULT'),
225
+ zIndex: '100',
226
+ },
227
+ /**
228
+ * Round the corners of our main content.
229
+ * Protip: Use this together with navbar, footer and `bg-blue` class on the body.
230
+ */
231
+ '.pagemain': {
232
+ backgroundColor: '#fff',
233
+ borderRadius: '2rem',
234
+ overflow: 'hidden',
235
+ },
236
+ });
237
+ addUtilities({
238
+ // imitates a bold font, but doesn't cause layout due to element width change like with font-weight
239
+ // Note that this CSS isn't standardized, but it works in Fx, Chrome, Safari and Edge
240
+ '.fake-font-bold': {
241
+ '-webkit-text-stroke': '1px',
242
+ },
243
+ });
244
+ }),
245
+ plugin(function ({ addBase }) {
246
+ addBase(
247
+ fonts.map((font) => ({
248
+ '@font-face': {
249
+ fontFamily,
250
+ fontWeight: font.fontWeight,
251
+ fontStyle: font.fontStyle,
252
+ src: `url('${opts.fontBasePath}${font.url}') format('woff2')`,
253
+ fontDisplay: 'swap',
254
+ },
255
+ })),
256
+ );
257
+ }),
258
+ ],
259
+ corePlugins: {
260
+ container: false,
239
261
  },
240
- extend: {
241
- maxWidth: {
242
- // Override Tailwinds default prose width of 60 chars to 48. Roughly 590 pixels
243
- prose: '48ch',
244
- },
245
- width: {
246
- prose: '48ch',
247
- },
248
- screens: {
249
- // replicate the smaller than breakpoint from Windi. Even though we are mobile first, it is really nice with an escape hatch sometimes
250
- '<md': { max: '767.9px' },
251
- },
252
- spacing: {
253
- 18: '4.5rem',
262
+ theme: {
263
+ fontSize: {
264
+ sm: '0.875rem',
265
+ base: '1rem',
266
+ lg: '1.125rem', // 18px
267
+ xl: '1.25rem', // 20px
268
+ '2xl': '1.5rem', // 24px
269
+ '3xl': '1.875rem', // 28px
270
+ '4xl': '2rem', // 32px
271
+ '5xl': '2.5rem', // 40px
254
272
  },
255
- colors: {
256
- black: '#333',
257
- white: '#fff',
258
- gray: {
259
- // TODO: Figure out how to work this into the color scale
260
- concrete: '#f1f1f1',
261
- // Gray
262
- dark: '#595959',
263
- // Medium gray
264
- DEFAULT: '#818181',
265
- // Light gray
266
- light: '#E6E6E6',
273
+ extend: {
274
+ maxWidth: {
275
+ // Override Tailwinds default prose width of 60 chars to 48. Roughly 590 pixels
276
+ prose: '590px',
267
277
  },
268
- blue: {
269
- // light blue
270
- lightest: '#DEEFF5',
271
- // OBOS Sky
272
- light: '#BEDFEC',
273
- // OBOS Blue/Primary brand
274
- DEFAULT: '#0047BA',
275
- // OBOS Ocean
276
- dark: '#002169',
278
+ width: {
279
+ prose: '590px',
277
280
  },
278
- green: {
279
- // light green
280
- lightest: '#E6F5F0',
281
- // OBOS Mint
282
- light: '#CDECE2',
283
- // OBOS Green/Primary brand
284
- DEFAULT: '#008761',
285
- // OBOS Forest
286
- dark: '#00524C',
281
+ screens: {
282
+ // replicate the smaller than breakpoint from Windi. Even though we are mobile first, it is really nice with an escape hatch sometimes
283
+ '<md': { max: '767.9px' },
287
284
  },
288
- red: {
289
- // error red
290
- light: '#faedef',
291
- DEFAULT: '#cd465e',
285
+ spacing: {
286
+ 18: '4.5rem',
292
287
  },
293
- orange: {
294
- light: '#f8e5c9',
295
- DEFAULT: '#e8a74a',
288
+ colors: {
289
+ black: '#333',
290
+ white: '#fff',
291
+ gray: {
292
+ // TODO: Figure out how to work this into the color scale
293
+ concrete: '#f1f1f1',
294
+ // Gray
295
+ dark: '#595959',
296
+ // Medium gray
297
+ DEFAULT: '#818181',
298
+ // Light gray
299
+ light: '#E6E6E6',
300
+ },
301
+ blue: {
302
+ // light blue
303
+ lightest: '#DEEFF5',
304
+ // OBOS Sky
305
+ light: '#BEDFEC',
306
+ // OBOS Blue/Primary brand
307
+ DEFAULT: '#0047BA',
308
+ // OBOS Ocean
309
+ dark: '#002169',
310
+ },
311
+ green: {
312
+ // light green
313
+ lightest: '#E6F5F0',
314
+ // OBOS Mint
315
+ light: '#CDECE2',
316
+ // OBOS Green/Primary brand
317
+ DEFAULT: '#008761',
318
+ // OBOS Forest
319
+ dark: '#00524C',
320
+ },
321
+ red: {
322
+ // error red
323
+ light: '#faedef',
324
+ DEFAULT: '#cd465e',
325
+ },
326
+ orange: {
327
+ light: '#f8e5c9',
328
+ DEFAULT: '#e8a74a',
329
+ },
330
+ yellow: {
331
+ // open house
332
+ DEFAULT: '#fff5d2',
333
+ },
296
334
  },
297
- yellow: {
298
- // open house
299
- DEFAULT: '#fff5d2',
335
+ fontFamily: {
336
+ sans: [fontFamily, 'sans-serif'],
300
337
  },
301
- },
302
- fontFamily: {
303
- sans: ['Gordita', 'sans-serif'],
304
- },
305
- boxShadow: {
306
- DEFAULT: '0 6px 4px 0 rgba(0, 33, 105, 0.25)',
307
- },
308
- typography: (theme) => ({
309
- DEFAULT: {
310
- css: {
311
- '--tw-prose-headings': theme('colors.black'),
312
- '--tw-prose-lead': theme('colors.black'),
313
- color: theme('colors.black'),
314
- maxWidth: '48ch',
315
- a: {
316
- fontWeight: 400,
317
- },
318
- h1: {
319
- fontWeight: 'bold',
320
- },
321
- h2: {
322
- fontWeight: 'bold',
323
- },
324
- h3: {
325
- fontWeight: 'bold',
326
- },
327
- h4: {
328
- fontWeight: 'bold',
329
- },
330
- '[class~="lead"]': {
331
- fontWeight: 500,
338
+ boxShadow: {
339
+ DEFAULT: '0 6px 4px 0 rgba(0, 33, 105, 0.25)',
340
+ },
341
+ typography: (theme) => ({
342
+ DEFAULT: {
343
+ css: {
344
+ '--tw-prose-headings': theme('colors.black'),
345
+ '--tw-prose-lead': theme('colors.black'),
346
+ // TODO: Increase bullet size. See design sketches
347
+ '--tw-prose-bullets': theme('colors.green.DEFAULT'),
348
+ color: theme('colors.black'),
349
+ maxWidth: theme('maxWidth.prose'),
350
+ a: {
351
+ fontWeight: 400,
352
+ },
353
+ h1: {
354
+ fontWeight: 'bold',
355
+ },
356
+ h2: {
357
+ fontWeight: 'bold',
358
+ },
359
+ h3: {
360
+ fontWeight: 'bold',
361
+ },
362
+ h4: {
363
+ fontWeight: 'bold',
364
+ },
365
+ li: {
366
+ marginTop: '1.5em',
367
+ marginBottom: '1.5em',
368
+ },
369
+ '[class~="lead"]': {
370
+ fontWeight: 500,
371
+ },
332
372
  },
333
373
  },
334
- },
335
- }),
374
+ }),
375
+ },
336
376
  },
337
- },
377
+ };
338
378
  };