@digigov/css 1.0.0-rc → 1.0.0-rc.2

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 (69) hide show
  1. package/defaultTheme/footer.json +5 -5
  2. package/defaultTheme/typography.json +22 -2
  3. package/dist/base/index.css +1 -3
  4. package/dist/base.js +1 -1
  5. package/dist/components.js +1 -1
  6. package/dist/digigov.css +3 -5
  7. package/dist/utilities/index.css +1 -1
  8. package/dist/utilities.js +1 -1
  9. package/index.js +1 -1
  10. package/package.json +6 -7
  11. package/postcss.config.js +15 -14
  12. package/src/base/index.css +3 -0
  13. package/src/base/postcss.config.js +23 -22
  14. package/src/base/tailwind.config.js +19 -15
  15. package/src/components/accessibility-menu.css +8 -3
  16. package/src/components/accordion.css +67 -13
  17. package/src/components/admin-header.css +27 -1
  18. package/src/components/admin-layout.css +6 -0
  19. package/src/components/autocomplete.css +12 -9
  20. package/src/components/bottom-info.css +2 -1
  21. package/src/components/button.css +86 -27
  22. package/src/components/card.css +30 -15
  23. package/src/components/checkboxes.css +56 -10
  24. package/src/components/chip.css +35 -15
  25. package/src/components/copy-to-clipboard.css +52 -30
  26. package/src/components/drawer.css +17 -26
  27. package/src/components/dropdown.css +52 -52
  28. package/src/components/filter.css +71 -63
  29. package/src/components/footer.css +29 -23
  30. package/src/components/form.css +70 -47
  31. package/src/components/header.css +86 -32
  32. package/src/components/hidden.css +3 -0
  33. package/src/components/index.css +3 -0
  34. package/src/components/kitchensink.css +2 -2
  35. package/src/components/layout.css +21 -22
  36. package/src/components/loader.css +11 -22
  37. package/src/components/masthead.css +78 -0
  38. package/src/components/misc.css +17 -41
  39. package/src/components/modal.css +10 -3
  40. package/src/components/nav.css +93 -126
  41. package/src/components/notification-banner.css +32 -10
  42. package/src/components/pagination.css +38 -24
  43. package/src/components/panel.css +4 -4
  44. package/src/components/phase-banner.css +1 -7
  45. package/src/components/postcss.config.js +15 -16
  46. package/src/components/radios.css +34 -25
  47. package/src/components/stack.css +66 -0
  48. package/src/components/stepnav.css +34 -10
  49. package/src/components/summary-list.css +22 -15
  50. package/src/components/svg-icons.css +2 -62
  51. package/src/components/table.css +75 -56
  52. package/src/components/tabs.css +19 -0
  53. package/src/components/tailwind.config.js +12 -6
  54. package/src/components/task-list.css +28 -15
  55. package/src/components/timeline.css +21 -6
  56. package/src/components/typography.css +104 -63
  57. package/src/components/warning-text.css +23 -0
  58. package/src/fonts.css +1 -1
  59. package/src/index.css +0 -2
  60. package/src/pages/admin-filtering-data.js +1 -1
  61. package/src/pages/dropdown.js +2 -2
  62. package/src/pages/form.js +1 -1
  63. package/src/pages/index.js +12 -10
  64. package/src/utilities/index.css +142 -22
  65. package/src/utilities/postcss.config.js +15 -16
  66. package/src/utilities/tailwind.config.js +10 -1
  67. package/src/utilities/utilities.css +158 -34
  68. package/tailwind.config.js +20 -27
  69. package/themes.plugin.js +95 -100
package/themes.plugin.js CHANGED
@@ -6,92 +6,20 @@ const postcssJs = require("postcss-js");
6
6
 
7
7
  const prefix = "govgr";
8
8
  const mediaQueriesMapping = {
9
- xs: "",
9
+ xs: "@media (min-width: 0px)",
10
10
  sm: "@media (min-width: 640px)",
11
11
  md: "@media (min-width: 768px)",
12
12
  lg: "@media (min-width: 1024px)",
13
13
  print: "@media print",
14
14
  };
15
15
 
16
- function hexToRGB(hex) {
17
- var r = parseInt(hex.slice(1, 3), 16),
18
- g = parseInt(hex.slice(3, 5), 16),
19
- b = parseInt(hex.slice(5, 7), 16);
20
-
21
- return r + ", " + g + ", " + b;
22
- }
23
16
  let hasRun = false;
24
17
 
25
- function addThemes({ addBase, addComponents, theme, config }) {
18
+ module.exports = function addThemes({ addBase, config }) {
26
19
  if (hasRun) {
27
20
  return;
28
21
  }
29
22
  hasRun = true;
30
- function extractColorVars(colorObj, colorGroup = "") {
31
- return Object.keys(colorObj).reduce((vars, colorKey) => {
32
- const value = colorObj[colorKey];
33
- const colorName =
34
- colorKey == "default"
35
- ? `--color${colorGroup}`
36
- : `--color${colorGroup}-${colorKey}`;
37
- const newVars =
38
- typeof value === "string"
39
- ? {
40
- [colorName]: value,
41
- [`${colorName}-rgb`]: hexToRGB(value),
42
- }
43
- : extractColorVars(value, `-${colorKey}`);
44
- return { ...vars, ...newVars };
45
- }, {});
46
- }
47
-
48
- function extractMediaQueriesFromComponentVars(componentObj, customTheme) {
49
- let mediaObj = {};
50
- Object.keys(componentObj).forEach((componentClass) => {
51
- Object.keys(componentObj[componentClass]).forEach((componentAttr) => {
52
- Object.keys(componentObj[componentClass][componentAttr]).forEach(
53
- (componentMedia) => {
54
- const newAttrKey = `--${componentClass}-${componentAttr}`;
55
- const newAttrValue =
56
- componentObj[componentClass][componentAttr][componentMedia];
57
- const newAttr = { [newAttrKey]: newAttrValue };
58
- const newClass = `.${prefix}-${componentClass}`;
59
- const newMedia = mediaQueriesMapping[componentMedia];
60
- const newTheme =
61
- customTheme === defaultTheme ? "" : `.${customTheme}`;
62
-
63
- if (mediaObj[newMedia]) {
64
- if (mediaObj[newMedia][newTheme][newClass]) {
65
- mediaObj[newMedia][newTheme][newClass][newAttrKey] =
66
- newAttrValue;
67
- } else {
68
- mediaObj[newMedia][newTheme][newClass] = newAttr;
69
- }
70
- } else {
71
- mediaObj[newMedia] = { [newTheme]: { [newClass]: newAttr } };
72
- }
73
- }
74
- );
75
- });
76
- });
77
- return mediaObj;
78
- }
79
-
80
- function extractGlobalVars(globalVarsObj) {
81
- return Object.keys(globalVarsObj).reduce((vars, varKey) => {
82
- const value = globalVarsObj[varKey];
83
- vars[`--${varKey}`] = value;
84
- return vars;
85
- }, {});
86
- }
87
- function extractVars(themeObj) {
88
- const colorVars = extractColorVars(themeObj.colors);
89
- const globalVars =
90
- themeObj.variables && themeObj.variables.globals
91
- ? extractGlobalVars(themeObj.variables.globals)
92
- : {};
93
- return { ...colorVars, ...globalVars };
94
- }
95
23
 
96
24
  let base = {};
97
25
  const themes = config("themes");
@@ -99,44 +27,35 @@ function addThemes({ addBase, addComponents, theme, config }) {
99
27
  for (const customTheme in themes) {
100
28
  const customThemeObject = require(themes[customTheme]);
101
29
  if (customThemeObject.overrides) {
102
- if (config("mode") === "jit") {
103
- console.log("Loading theme css from source...");
104
- const css = fs
105
- .readFileSync(
106
- path.resolve(
107
- path.dirname(themes[customTheme]),
108
- "overrides/index.css"
109
- )
110
- )
111
- .toString();
112
- const ctx = {};
113
- const { plugins, options } = postcssrc.sync(ctx);
114
- const result = postcss(plugins).process(css, options).root;
115
- const cssJs = postcssJs.objectify(result);
116
- base[`.${customTheme}`] = cssJs;
117
- } else {
118
- customThemeObject.overrides.forEach((override) => {
119
- const cssJs = require(path.resolve(
30
+ console.log("Loading theme css from source...");
31
+ const css = fs
32
+ .readFileSync(
33
+ path.resolve(
120
34
  path.dirname(themes[customTheme]),
121
- override
122
- ));
123
- base[`.${customTheme}`] = cssJs;
124
- });
125
- }
35
+ "overrides/index.css",
36
+ ),
37
+ )
38
+ .toString();
39
+ const ctx = {};
40
+ const { plugins, options } = postcssrc.sync(ctx);
41
+ const result = postcss(plugins).process(css, options).result.root;
42
+ const cssJs = postcssJs.objectify(result);
43
+ base[`.${customTheme}`] = cssJs;
126
44
  }
127
45
  if (customTheme === defaultTheme) {
128
46
  base[`:root,:root.${customTheme},::before,::after`] =
129
47
  extractVars(customThemeObject);
130
48
  } else {
131
49
  base[
132
- `:root.${customTheme},.${customTheme} *::before,.${customTheme} *::after`
50
+ `:root.${customTheme},.${customTheme},.${customTheme} *::before,.${customTheme} *::after`
133
51
  ] = extractVars(customThemeObject);
134
52
  }
135
53
 
136
54
  if (customThemeObject.variables && customThemeObject.variables.components) {
137
55
  const extractedVariables = extractMediaQueriesFromComponentVars(
138
56
  customThemeObject.variables.components,
139
- customTheme
57
+ customTheme,
58
+ defaultTheme,
140
59
  );
141
60
  Object.keys(extractedVariables).forEach((key) => {
142
61
  if (base[key]) {
@@ -148,6 +67,82 @@ function addThemes({ addBase, addComponents, theme, config }) {
148
67
  }
149
68
  }
150
69
  addBase(base);
70
+ };
71
+
72
+ function extractVars(themeObj) {
73
+ const colorVars = extractColorVars(themeObj.colors);
74
+ const globalVars =
75
+ themeObj.variables && themeObj.variables.globals
76
+ ? extractGlobalVars(themeObj.variables.globals)
77
+ : {};
78
+ return { ...colorVars, ...globalVars };
151
79
  }
152
80
 
153
- module.exports = addThemes;
81
+ function extractColorVars(colorObj, colorGroup = "") {
82
+ return Object.keys(colorObj).reduce((vars, colorKey) => {
83
+ const value = colorObj[colorKey];
84
+ const colorName =
85
+ colorKey == "default"
86
+ ? `--color${colorGroup}`
87
+ : `--color${colorGroup}-${colorKey}`;
88
+ const newVars =
89
+ typeof value === "string"
90
+ ? {
91
+ [colorName]: value,
92
+ [`${colorName}-rgb`]: hexToRGB(value),
93
+ }
94
+ : extractColorVars(value, `-${colorKey}`);
95
+ return { ...vars, ...newVars };
96
+ }, {});
97
+ }
98
+
99
+ function extractGlobalVars(globalVarsObj) {
100
+ return Object.keys(globalVarsObj).reduce((vars, varKey) => {
101
+ const value = globalVarsObj[varKey];
102
+ vars[`--${varKey}`] = value;
103
+ return vars;
104
+ }, {});
105
+ }
106
+
107
+ function hexToRGB(hex) {
108
+ const r = parseInt(hex.slice(1, 3), 16),
109
+ g = parseInt(hex.slice(3, 5), 16),
110
+ b = parseInt(hex.slice(5, 7), 16);
111
+
112
+ return r + ", " + g + ", " + b;
113
+ }
114
+
115
+ function extractMediaQueriesFromComponentVars(
116
+ componentObj,
117
+ customTheme,
118
+ defaultTheme,
119
+ ) {
120
+ let mediaObj = {};
121
+ Object.keys(componentObj).forEach((componentClass) => {
122
+ Object.keys(componentObj[componentClass]).forEach((componentAttr) => {
123
+ Object.keys(componentObj[componentClass][componentAttr]).forEach(
124
+ (componentMedia) => {
125
+ const newAttrKey = `--${componentClass}-${componentAttr}`;
126
+ const newAttrValue =
127
+ componentObj[componentClass][componentAttr][componentMedia];
128
+ const newAttr = { [newAttrKey]: newAttrValue };
129
+ const newClass = `.${prefix}-${componentClass}`;
130
+ const newMedia = mediaQueriesMapping[componentMedia];
131
+ const newTheme =
132
+ customTheme === defaultTheme ? "" : `.${customTheme}`;
133
+
134
+ if (mediaObj[newMedia]) {
135
+ if (mediaObj[newMedia][newTheme][newClass]) {
136
+ mediaObj[newMedia][newTheme][newClass][newAttrKey] = newAttrValue;
137
+ } else {
138
+ mediaObj[newMedia][newTheme][newClass] = newAttr;
139
+ }
140
+ } else {
141
+ mediaObj[newMedia] = { [newTheme]: { [newClass]: newAttr } };
142
+ }
143
+ },
144
+ );
145
+ });
146
+ });
147
+ return mediaObj;
148
+ }