@obosbbl/grunnmuren-tailwind 0.1.0 → 0.2.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 +26 -1
  2. package/package.json +1 -1
  3. package/tailwind-base.cjs +232 -202
package/README.md CHANGED
@@ -12,8 +12,33 @@ 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 }),
30
+ // content: [ ... ]
18
31
  };
19
32
  ```
33
+
34
+ ### Fonts
35
+
36
+ The preset includes font declarations. You'll have to setup your app so it serves the necessary [font files](../react/public/fonts/) at the path `/fonts/`. See the [preset implementation](./tailwind-base.cjs).
37
+
38
+ ## Options
39
+
40
+ The preset supports the following options:
41
+
42
+ | Name | Default value | Description |
43
+ | ------------- | ------------- | -------------------------------------------- |
44
+ | useLegacyFont | `false` | Whether to use the fonts from the old design |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@obosbbl/grunnmuren-tailwind",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Grunnmuren Tailwind preset",
5
5
  "license": "MIT",
6
6
  "type": "commonjs",
package/tailwind-base.cjs CHANGED
@@ -1,7 +1,7 @@
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',
@@ -24,12 +24,35 @@ const fonts = [
24
24
  },
25
25
  ];
26
26
 
27
+ const obosFonts = [
28
+ {
29
+ fontWeight: 400,
30
+ fontStyle: 'normal',
31
+ url: '/fonts/OBOSText-Regular.woff2',
32
+ },
33
+ {
34
+ fontWeight: 400,
35
+ fontStyle: 'italic',
36
+ url: '/fonts/OBOSText-Italic.woff2',
37
+ },
38
+ {
39
+ fontWeight: 500,
40
+ fontStyle: 'normal',
41
+ url: '/fonts/OBOSText-Medium.woff2',
42
+ },
43
+ {
44
+ fontWeight: 700,
45
+ fontStyle: 'normal',
46
+ url: '/fonts/OBOSText-Bold.woff2',
47
+ },
48
+ ];
49
+
27
50
  const button = plugin(function ({ addComponents }) {
28
51
  // adds a shade on the button when hovered
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,237 @@ 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 }) => {
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
+ });
193
+ addComponents({
194
+ '.container': {
195
+ width: '100%',
196
+ paddingLeft: '1rem',
197
+ paddingRight: '1rem',
198
+ marginLeft: 'auto',
199
+ marginRight: 'auto',
200
+ maxWidth: '90rem',
201
+ },
202
+ '.container-prose': {
203
+ width: '100%',
204
+ paddingLeft: '1rem',
205
+ paddingRight: '1rem',
206
+ marginLeft: 'auto',
207
+ marginRight: 'auto',
208
+ maxWidth: '37rem',
209
+ },
210
+ // that thin blue line at the top
211
+ '.topline::before': {
212
+ display: 'block',
213
+ width: '100%',
214
+ height: '5px',
215
+ content: '""',
216
+ position: 'fixed',
217
+ left: '0',
218
+ top: '0',
219
+ right: '0',
220
+ backgroundColor: theme('colors.blue.DEFAULT'),
221
+ zIndex: '100',
222
+ },
223
+ /**
224
+ * Round the corners of our main content.
225
+ * Protip: Use this together with navbar, footer and `bg-blue` class on the body.
226
+ */
227
+ '.pagemain': {
228
+ backgroundColor: '#fff',
229
+ borderRadius: '2rem',
230
+ overflow: 'hidden',
231
+ },
232
+ });
233
+ addUtilities({
234
+ // imitates a bold font, but doesn't cause layout due to element width change like with font-weight
235
+ // Note that this CSS isn't standardized, but it works in Fx, Chrome, Safari and Edge
236
+ '.fake-font-bold': {
237
+ '-webkit-text-stroke': '1px',
238
+ },
239
+ });
240
+ }),
241
+ plugin(function ({ addBase }) {
242
+ addBase(
243
+ fonts.map((font) => ({
244
+ '@font-face': {
245
+ fontFamily,
246
+ fontWeight: font.fontWeight,
247
+ fontStyle: font.fontStyle,
248
+ src: `url('${font.url}') format('woff2')`,
249
+ fontDisplay: 'swap',
250
+ },
251
+ })),
252
+ );
253
+ }),
254
+ ],
255
+ corePlugins: {
256
+ container: false,
239
257
  },
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',
258
+ theme: {
259
+ fontSize: {
260
+ sm: '0.875rem',
261
+ base: '1rem',
262
+ lg: '1.125rem', // 18px
263
+ xl: '1.25rem', // 20px
264
+ '2xl': '1.5rem', // 24px
265
+ '3xl': '1.875rem', // 28px
266
+ '4xl': '2rem', // 32px
267
+ '5xl': '2.5rem', // 40px
254
268
  },
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',
269
+ extend: {
270
+ maxWidth: {
271
+ // Override Tailwinds default prose width of 60 chars to 48. Roughly 590 pixels
272
+ prose: '590px',
267
273
  },
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',
274
+ width: {
275
+ prose: '590px',
277
276
  },
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',
277
+ screens: {
278
+ // replicate the smaller than breakpoint from Windi. Even though we are mobile first, it is really nice with an escape hatch sometimes
279
+ '<md': { max: '767.9px' },
287
280
  },
288
- red: {
289
- // error red
290
- light: '#faedef',
291
- DEFAULT: '#cd465e',
281
+ spacing: {
282
+ 18: '4.5rem',
292
283
  },
293
- orange: {
294
- light: '#f8e5c9',
295
- DEFAULT: '#e8a74a',
284
+ colors: {
285
+ black: '#333',
286
+ white: '#fff',
287
+ gray: {
288
+ // TODO: Figure out how to work this into the color scale
289
+ concrete: '#f1f1f1',
290
+ // Gray
291
+ dark: '#595959',
292
+ // Medium gray
293
+ DEFAULT: '#818181',
294
+ // Light gray
295
+ light: '#E6E6E6',
296
+ },
297
+ blue: {
298
+ // light blue
299
+ lightest: '#DEEFF5',
300
+ // OBOS Sky
301
+ light: '#BEDFEC',
302
+ // OBOS Blue/Primary brand
303
+ DEFAULT: '#0047BA',
304
+ // OBOS Ocean
305
+ dark: '#002169',
306
+ },
307
+ green: {
308
+ // light green
309
+ lightest: '#E6F5F0',
310
+ // OBOS Mint
311
+ light: '#CDECE2',
312
+ // OBOS Green/Primary brand
313
+ DEFAULT: '#008761',
314
+ // OBOS Forest
315
+ dark: '#00524C',
316
+ },
317
+ red: {
318
+ // error red
319
+ light: '#faedef',
320
+ DEFAULT: '#cd465e',
321
+ },
322
+ orange: {
323
+ light: '#f8e5c9',
324
+ DEFAULT: '#e8a74a',
325
+ },
326
+ yellow: {
327
+ // open house
328
+ DEFAULT: '#fff5d2',
329
+ },
296
330
  },
297
- yellow: {
298
- // open house
299
- DEFAULT: '#fff5d2',
331
+ fontFamily: {
332
+ sans: [fontFamily, 'sans-serif'],
300
333
  },
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,
334
+ boxShadow: {
335
+ DEFAULT: '0 6px 4px 0 rgba(0, 33, 105, 0.25)',
336
+ },
337
+ typography: (theme) => ({
338
+ DEFAULT: {
339
+ css: {
340
+ '--tw-prose-headings': theme('colors.black'),
341
+ '--tw-prose-lead': theme('colors.black'),
342
+ color: theme('colors.black'),
343
+ maxWidth: theme('maxWidth.prose'),
344
+ a: {
345
+ fontWeight: 400,
346
+ },
347
+ h1: {
348
+ fontWeight: 'bold',
349
+ },
350
+ h2: {
351
+ fontWeight: 'bold',
352
+ },
353
+ h3: {
354
+ fontWeight: 'bold',
355
+ },
356
+ h4: {
357
+ fontWeight: 'bold',
358
+ },
359
+ '[class~="lead"]': {
360
+ fontWeight: 500,
361
+ },
332
362
  },
333
363
  },
334
- },
335
- }),
364
+ }),
365
+ },
336
366
  },
337
- },
367
+ };
338
368
  };