|
| 1 | +TodoMVC app styled following the [SUIT's design principles](https://github.com/suitcss/suit/). |
| 2 | + |
| 3 | +## Installation |
| 4 | + |
| 5 | +* clone this repo |
| 6 | +* run `npm install` |
| 7 | + |
| 8 | +## Build |
| 9 | + |
| 10 | +Run `npm run build`. |
| 11 | + |
| 12 | +The script will build your [themes](#themes) into the `build` folder. |
| 13 | + |
| 14 | +## Folders structure |
| 15 | + |
| 16 | +The app source code is in `src`. |
| 17 | +Here you have the following structure: |
| 18 | + |
| 19 | +``` |
| 20 | +base |
| 21 | +components |
| 22 | +views |
| 23 | +utils |
| 24 | +themes |
| 25 | +``` |
| 26 | + |
| 27 | +In general it is a good idea to build standalone pieces and keep theme specific styles in `themes`. |
| 28 | + |
| 29 | +This approach is recommended even if you have a single theme app since you should always have alternative themes for accessibility reasons. |
| 30 | +You can read more about this topic in the [themes](#themes) section. |
| 31 | + |
| 32 | +## base |
| 33 | + |
| 34 | +Suggested maximum specificity: `0011` |
| 35 | + |
| 36 | +Contains `suitcss-base` and generic rules or resets. |
| 37 | +<br>At this point you may want to only target elements and keep the specificity very low. |
| 38 | + |
| 39 | +## components |
| 40 | + |
| 41 | +Suggested maximum specificity: `0020` |
| 42 | + |
| 43 | +Contains suitcss components. |
| 44 | +<br>It is a good idea to keep components simple and reusable. |
| 45 | + |
| 46 | +Components are standalone, they just define variables that can be overriden in a Theme/Site file. |
| 47 | + |
| 48 | +For consistency we suggest to use the following convention for properties names: |
| 49 | + |
| 50 | +``` |
| 51 | +--ComponentName[-descendant|--modifier][-onState]-(cssProperty|variableName) |
| 52 | +``` |
| 53 | + |
| 54 | + |
| 55 | +Examples |
| 56 | + |
| 57 | +``` |
| 58 | +--ComponentName-backgroundColor |
| 59 | +--ComponentName-descendant-backgroundColor |
| 60 | +--ComponentName--modifier-backgroundColor |
| 61 | +--ComponentName-onHover-backgroundColor |
| 62 | +--ComponentName-descendant-onHover-backgroundColor |
| 63 | +... |
| 64 | +``` |
| 65 | + |
| 66 | +Example component `components/MyComponent/index.css`: |
| 67 | + |
| 68 | + |
| 69 | +```css |
| 70 | +/** @define MyComponent */ |
| 71 | + |
| 72 | +:root { |
| 73 | + --MyComponent-color: currentColor; |
| 74 | + --MyComponent-fontFamily: inherit; |
| 75 | + --MyComponent-fontSize: inherit; |
| 76 | +} |
| 77 | + |
| 78 | +.MyComponent { |
| 79 | + color: var(--MyComponent-color); |
| 80 | + font-family: var(--MyComponent-fontFamily); |
| 81 | + font-size: var(--MyComponent-fontSize); |
| 82 | +} |
| 83 | + |
| 84 | +.MyComponent-descendant { |
| 85 | + padding: var(--MyComponent-descendant-padding); |
| 86 | +} |
| 87 | + |
| 88 | +@media (--MyComponent-mediaLarge) { |
| 89 | + .MyComponent-descendant { |
| 90 | + display: none; |
| 91 | + } |
| 92 | +} |
| 93 | +``` |
| 94 | + |
| 95 | +Components should use but not define their own custom media queries. |
| 96 | + |
| 97 | +In the example `--MyComponent-mediaLarge` will be defined at the theme level. |
| 98 | + |
| 99 | +Read more about [components](https://github.com/suitcss/suit/blob/master/doc/components.md). |
| 100 | + |
| 101 | +## views |
| 102 | + |
| 103 | +No suggested maximum specificity. |
| 104 | + |
| 105 | +Views are page (or portions of it) specific styles. |
| 106 | +<br>Those styles usually are used to make small tweaks to a specific page or component in a specific context. |
| 107 | + |
| 108 | +## utils |
| 109 | + |
| 110 | +Specificity: `!important`. |
| 111 | + |
| 112 | +Utility classes are one off and *final* rules. |
| 113 | + |
| 114 | +Read more about [utilities](https://github.com/suitcss/suit/blob/master/doc/utilities.md). |
| 115 | + |
| 116 | +## themes |
| 117 | + |
| 118 | +Themes is the place where you customize your components and app. |
| 119 | +<br>Each theme is a folder in `themes` and defines theme specific variables. |
| 120 | + |
| 121 | +Customization usually happens by mapping component properties to theme specific ones. |
| 122 | + |
| 123 | +```css |
| 124 | +:root { |
| 125 | + --MyComponent-color: var(--color-primary); |
| 126 | +} |
| 127 | +``` |
| 128 | + |
| 129 | +A theme folder reproduces the app structure. |
| 130 | +Say that you are making a `ThemeName` theme: |
| 131 | + |
| 132 | +``` |
| 133 | +ThemeName |
| 134 | + - base |
| 135 | + - components |
| 136 | + - utils |
| 137 | + - views |
| 138 | + - variables |
| 139 | +``` |
| 140 | + |
| 141 | +### variables |
| 142 | + |
| 143 | +Variables is the place where you define theme properties to use in the maps. |
| 144 | + |
| 145 | +``` |
| 146 | +variables |
| 147 | + - color.css |
| 148 | + - font.css |
| 149 | + - spacing.css |
| 150 | + - index.css |
| 151 | +``` |
| 152 | + |
| 153 | +Properties are namespaced using the file name `themes/ThemeName/variables/color.css`: |
| 154 | + |
| 155 | +```css |
| 156 | +:root { |
| 157 | + --color-primary: black; |
| 158 | + --color-secondary: blue; |
| 159 | + --color-inverse: white; |
| 160 | + /* ... */ |
| 161 | +} |
| 162 | +``` |
| 163 | + |
| 164 | +`index.css` includes them all `themes/ThemeName/variables/index.css`: |
| 165 | + |
| 166 | +```css |
| 167 | +@import "./color"; |
| 168 | +@import "./font"; |
| 169 | +@import "./size"; |
| 170 | +``` |
| 171 | + |
| 172 | +### theme parts |
| 173 | + |
| 174 | +base, components, utils and views contain a single `index.css` file where we include the corrispective file from the app, variables and where we do the mapping. |
| 175 | + |
| 176 | +Example: |
| 177 | + |
| 178 | +```css |
| 179 | +/* themes/ThemeName/components/index.css */ |
| 180 | + |
| 181 | +/* import the generic components from the app */ |
| 182 | +@import "../../../components"; |
| 183 | + |
| 184 | +/* import the variables */ |
| 185 | +@import "../variables"; |
| 186 | + |
| 187 | +/* optionally import theme only components or overrides */ |
| 188 | +/* @import "./Button"; */ |
| 189 | + |
| 190 | +/* |
| 191 | + Create a map of component variables and `../variables/` |
| 192 | + N.B. the maps could as well live in separate files e.g. in "./Button/index.css" |
| 193 | +*/ |
| 194 | + |
| 195 | + |
| 196 | +/** MyComponent */ |
| 197 | + |
| 198 | +:root { |
| 199 | + --MyComponent-color: var(--color-primary); |
| 200 | + --MyComponent-fontFamily: var(--font-family-sansSerif); |
| 201 | + --MyComponent-fontSize: var(--font-size-medium); |
| 202 | +} |
| 203 | + |
| 204 | +@custom-media --MyComponent-mediaLarge (min-width: 960px); |
| 205 | + |
| 206 | + |
| 207 | +/** AnotherComponent */ |
| 208 | +``` |
0 commit comments