@sitecore-feaas/clientside 0.1.55 → 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.
- package/README.md +538 -55
- package/build/ui/FEAASExternal.js +8 -7
- package/build/ui/FEAASExternal.js.map +1 -1
- package/dist/browser/react.cjs +4 -4
- package/dist/browser/react.cjs.map +2 -2
- package/dist/browser/react.esm.js +3 -3
- package/dist/browser/react.esm.js.map +1 -1
- package/dist/node/react.cjs +4 -4
- package/dist/node/react.cjs.map +2 -2
- package/dist/node/react.esm.js +3 -3
- package/dist/node/react.esm.js.map +2 -2
- package/package.json +1 -1
- package/react.cjs +4 -4
- package/react.cjs.map +2 -2
- package/react.js +4 -4
- package/react.js.map +2 -2
- package/src/ui/FEAASExternal.tsx +7 -6
- package/types/tsbuildinfo +1 -1
- package/types/tsbuildinfo_ui +1 -1
- package/types/ui/FEAASExternal.d.ts.map +1 -1
package/README.md
CHANGED
|
@@ -19,16 +19,27 @@ data.
|
|
|
19
19
|
|
|
20
20
|
## Usage
|
|
21
21
|
|
|
22
|
-
### React
|
|
22
|
+
### React
|
|
23
|
+
|
|
24
|
+
```jsx
|
|
25
|
+
import * as FEAAS from '@sitecore-feaas/clientside/react'
|
|
26
|
+
|
|
27
|
+
// fetch component from the cloud
|
|
28
|
+
return (
|
|
29
|
+
<FEAAS.Component component='...' version='...' revision='published' cdn='...' data={{ user: { name: 'John' } }} />
|
|
30
|
+
)
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### Web component
|
|
23
34
|
|
|
24
35
|
```javascript
|
|
25
36
|
import * as FEAAS '@sitecore-feaas/clientside';
|
|
26
37
|
|
|
27
38
|
// provide html template directly
|
|
28
|
-
<feaas-component template={`<p>Hello <var data-path="user.name" /></p>`} data={JSON.stringify({user: {name: "
|
|
39
|
+
<feaas-component template={`<p>Hello <var data-path="user.name" /></p>`} data={JSON.stringify({user: {name: "John"}})} />
|
|
29
40
|
|
|
30
41
|
// fetch component from the cloud
|
|
31
|
-
<feaas-component component="..." version="..." revision="
|
|
42
|
+
<feaas-component component="..." version="..." revision="published" cdn="..." data={JSON.stringify({user: {name: "John"}})} />
|
|
32
43
|
```
|
|
33
44
|
|
|
34
45
|
### JS Dom
|
|
@@ -47,7 +58,7 @@ const element = FEAAS.renderComponent({
|
|
|
47
58
|
version: '...',
|
|
48
59
|
revision: 'production',
|
|
49
60
|
cdn: '...',
|
|
50
|
-
data: { user: { name: '
|
|
61
|
+
data: { user: { name: 'John' } }
|
|
51
62
|
})
|
|
52
63
|
|
|
53
64
|
// inject element into DOM
|
|
@@ -57,7 +68,7 @@ document.body.appendChild(element)
|
|
|
57
68
|
// update element with new data
|
|
58
69
|
FEAAS.renderComponent(
|
|
59
70
|
{
|
|
60
|
-
data: { user: { name: '
|
|
71
|
+
data: { user: { name: 'Bill' } }
|
|
61
72
|
},
|
|
62
73
|
element
|
|
63
74
|
)
|
|
@@ -66,7 +77,7 @@ FEAAS.renderComponent(
|
|
|
66
77
|
const element = FEAAS.renderComponent(
|
|
67
78
|
{
|
|
68
79
|
template: `<p>Hello <var data-path="user.name" /></p>`,
|
|
69
|
-
data: { user: { name: '
|
|
80
|
+
data: { user: { name: 'Bill' } }
|
|
70
81
|
}
|
|
71
82
|
//, element // optionally provide target element here a
|
|
72
83
|
)
|
|
@@ -77,7 +88,7 @@ document.body.appendChild(element)
|
|
|
77
88
|
// update data in the element
|
|
78
89
|
FEAAS.renderComponent(
|
|
79
90
|
{
|
|
80
|
-
data: { user: { name: '
|
|
91
|
+
data: { user: { name: 'Sarah' } }
|
|
81
92
|
},
|
|
82
93
|
element
|
|
83
94
|
)
|
|
@@ -97,9 +108,9 @@ before it has finished loading, parsing and executing js.
|
|
|
97
108
|
|
|
98
109
|
```HTML
|
|
99
110
|
<!-- Use id=`feaas-stylesheet` for Clientside to deal with invalidation -->
|
|
100
|
-
<link rel='stylesheet' id='feaas-stylesheet' href='https://
|
|
111
|
+
<link rel='stylesheet' id='feaas-stylesheet' href='https://feaas.blob.core.windows.net.cloud/styles/:tenant_id/published.css' />
|
|
101
112
|
<!-- Include Clientside on the page OR as npm import inside your own code -->
|
|
102
|
-
<script src="
|
|
113
|
+
<script type="module" src="https://feaasstatic.blob.core.windows.net/packages/clientside/latest/browser/index.esm.js"></script>
|
|
103
114
|
```
|
|
104
115
|
|
|
105
116
|
### Linking stylesheet in Clientside app
|
|
@@ -117,38 +128,50 @@ import * as FEAAS from '@sitecore-feaas/clientside'
|
|
|
117
128
|
### Entrypoints
|
|
118
129
|
|
|
119
130
|
There are three different entrypoints for clientside: UI, React and Headless
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
the pickers and the embedded editor
|
|
131
|
+
|
|
132
|
+
1. The main entrypoint `@sitecore-feaas/clientside` targets the UI package which references frontend from components
|
|
133
|
+
monorepo. This includes both the core functionality and some ui components like the pickers and the embedded editor
|
|
123
134
|
2. The `@sitecore-feaas/clientside/react` entrypoint targets the React package which is similar to the main entrypoint
|
|
124
|
-
but also includes some components that use React as a dependency like external react components.
|
|
125
|
-
3. The `@sitecore-feaas/clientside/headless` entrypoint targets the Headless package which includes just the
|
|
126
|
-
|
|
135
|
+
but also includes some components that use React as a dependency like external react components.
|
|
136
|
+
3. The `@sitecore-feaas/clientside/headless` entrypoint targets the Headless package which includes just the core
|
|
137
|
+
functionality of clientside without any dependencies on frontend or react.
|
|
138
|
+
|
|
127
139
|
---
|
|
128
|
-
**NOTE 1:** React library is not included in any clientside package, we assume that it is already installed in the container that uses the `@sitecore-feaas/clientside/react` entrypoint. We mark React library as external in scripts/build.js
|
|
129
140
|
|
|
130
|
-
**NOTE
|
|
141
|
+
**NOTE 1:** React library is not included in any clientside package, we assume that it is already installed in the
|
|
142
|
+
container that uses the `@sitecore-feaas/clientside/react` entrypoint. We mark React library as external in
|
|
143
|
+
scripts/build.js
|
|
144
|
+
|
|
145
|
+
**NOTE 2:** UI has its own tsconfig that includes references to both `/frontend` and `/clientside`. Clientside main
|
|
146
|
+
tsconfig excludes `/ui` avoiding circular imports
|
|
131
147
|
|
|
132
148
|
---
|
|
133
149
|
|
|
134
150
|
### Bring your own code components
|
|
135
151
|
|
|
136
152
|
You can use Components clientside SDK to register and render your own code components to your FEAAS components.
|
|
137
|
-
Registration steps:
|
|
153
|
+
Registration steps:
|
|
154
|
+
|
|
138
155
|
- Install and import the Components React SDK to your App
|
|
139
|
-
|
|
156
|
+
|
|
157
|
+
```bash
|
|
140
158
|
npm install @sitecore-feaas/clientside
|
|
141
159
|
```
|
|
160
|
+
|
|
142
161
|
```typescript
|
|
143
|
-
import * as FEAAS from
|
|
162
|
+
import * as FEAAS from '@sitecore-feaas/clientside/react'
|
|
144
163
|
```
|
|
145
|
-
|
|
164
|
+
|
|
165
|
+
- Register your component via
|
|
166
|
+
|
|
146
167
|
```typescript
|
|
147
168
|
registerComponent(component, options)
|
|
148
169
|
```
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
170
|
+
|
|
171
|
+
`component` is the actual react component, `options` (optional) is a JSON Schema representation of your component
|
|
172
|
+
options containing the components props and other options. If not provided, the component will be registered as a
|
|
173
|
+
prop-less component. An example of `schema` is provided below:
|
|
174
|
+
|
|
152
175
|
```typescript
|
|
153
176
|
const options = {
|
|
154
177
|
name: 'My example component',
|
|
@@ -177,34 +200,494 @@ const options = {
|
|
|
177
200
|
|
|
178
201
|
Options may contain any of the bellow items:
|
|
179
202
|
|
|
180
|
-
<
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
Description:
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
Type:
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
Required: no
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
<
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
203
|
+
**Name**<br/> Type: string<br/> Required: no<br/> Description: Name of your Component as it will be shown to the user.
|
|
204
|
+
If not provided, will be function name in title case.
|
|
205
|
+
|
|
206
|
+
**Description**<br/> Type: string<br/> Required: no<br/> Description: Describe your Component and anything a user should
|
|
207
|
+
know when using it.
|
|
208
|
+
|
|
209
|
+
**Thumbnail**<br/> Type: url<br/> Required: no<br/> Description: A URL of a thumbnail image to be displayed in the
|
|
210
|
+
Builder. Should have some dimension guidelines.
|
|
211
|
+
|
|
212
|
+
**Group**<br/> Type: string<br/> Required: no<br/> Description: Used to group related Components together in the UI.
|
|
213
|
+
E.g. Typography
|
|
214
|
+
|
|
215
|
+
**Properties**<br/> Type: JSONSchema object<br/> Required: no<br/> Description: Inputs (Props) to be provided by the
|
|
216
|
+
user when embedding this Component.
|
|
217
|
+
|
|
218
|
+
**Required**<br/> Type: String Array<br/> Required: no<br/> Description: Array of keys from Inputs (Props) that should
|
|
219
|
+
be required
|
|
220
|
+
|
|
221
|
+
_We use React JSONSchema Form to generate a form for the component properties. You can read more about React JSONSchema
|
|
222
|
+
Form here:_ https://react-jsonschema-form.readthedocs.io
|
|
223
|
+
|
|
224
|
+
# Component anatomy
|
|
225
|
+
|
|
226
|
+
- It’s possible to edit/swap component without changing embedding HTML code (everything happens on CDN)
|
|
227
|
+
- User does not need to decide upfront if component will ever need to be edited in line, the only requirement is to
|
|
228
|
+
provide a unique id in embedding code
|
|
229
|
+
- Editing disables component FEAAS updates, but it’s possible to unfork component to return to original state/behavior
|
|
230
|
+
|
|
231
|
+
##Embedding
|
|
232
|
+
|
|
233
|
+
Components/versions are designed to be embedded on external pages. FEAAS approach allows then components to be updated
|
|
234
|
+
without changing the pages. There're multiple pathways for editing component:
|
|
235
|
+
|
|
236
|
+
- Editing component inside Builder
|
|
237
|
+
- Editing component externally (Pages or on the website)
|
|
238
|
+
|
|
239
|
+
In all of these cases the main requirement, is that no code is updated in place of embedding. The only time Components
|
|
240
|
+
is able to influence the embed site is initially by providing the code to copy and paste for the user. In case user
|
|
241
|
+
writes their embedding code by hand, there's no control at all. The system is designed to not require any changes.
|
|
242
|
+
|
|
243
|
+
```HTML
|
|
244
|
+
<feaas-component library="..." component="..." version="..." revision="production" data="{}" />
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
## Generated HTML
|
|
248
|
+
|
|
249
|
+
Components builder allows designer to create HTML templates and then style them. The elements inside components are the
|
|
250
|
+
usual suspects one can find in any web design editor - headings, paragraphs, pictures, containers. In addition to those,
|
|
251
|
+
the data model offers embedding of raw HTML islands and nesting components into each other. That last feature can be
|
|
252
|
+
used by designers to split big components into small, but it is also used internally to implement responsive/forked
|
|
253
|
+
components.
|
|
254
|
+
|
|
255
|
+
```HTML
|
|
256
|
+
<!-- A component with a single element is wrapped into a root element -->
|
|
257
|
+
<div class="-feaas">
|
|
258
|
+
<section>
|
|
259
|
+
<h1>Hello world</h1>
|
|
260
|
+
</section>
|
|
261
|
+
</div>
|
|
262
|
+
|
|
263
|
+
<!-- A component embedding another component version explicitly -->
|
|
264
|
+
<div class="-feaas">
|
|
265
|
+
<section>
|
|
266
|
+
<feaas-component component="component-id" version="version-id"></feaas-component>
|
|
267
|
+
</section>
|
|
268
|
+
</div>
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
## Responsive components
|
|
272
|
+
|
|
273
|
+
Each component has multiple versions, which make up a set of mutually exclusive respresentations of the same data.
|
|
274
|
+
Versions can be handily used to create a set of designs to be used for different screen sizes. In addition to embedding
|
|
275
|
+
a specific version of a component to the page, it is possible to embed a set of responsive components instead that
|
|
276
|
+
choose one of the versions based on window or container size.
|
|
277
|
+
|
|
278
|
+
Resposive component is a special aggregated version that analyzes all component versions and their breakpoints, and
|
|
279
|
+
ensure that for every breakpoint there's a fitting version. Responsive component version bundles all its versions into
|
|
280
|
+
one HTML file which hides its parts based on current css driven by the stylesheet. This approach allows weak binding to
|
|
281
|
+
definition of breakpoints, so breakpoint definitions can be changed after components are embedded.
|
|
282
|
+
|
|
283
|
+
Every time any of the versions in component is updated, responsive version is regenerated automatically.
|
|
284
|
+
|
|
285
|
+
```HTML
|
|
286
|
+
<!-- A responsive component that embeds version based on window or container size -->
|
|
287
|
+
<div class="-feaas">
|
|
288
|
+
<div class="-breakpoint--xs -breakpoint--sm">
|
|
289
|
+
<section>
|
|
290
|
+
<h1>Small version</h1>
|
|
291
|
+
</section>
|
|
292
|
+
</div>
|
|
293
|
+
<div class="-breakpoint--md -breakpoint--lg -breakpoint--xl">
|
|
294
|
+
<section>
|
|
295
|
+
<h1>Large version</h1>
|
|
296
|
+
</section>
|
|
297
|
+
</div>
|
|
298
|
+
</div>
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
## Component CDN storage
|
|
302
|
+
|
|
303
|
+
### Editing in builder
|
|
304
|
+
|
|
305
|
+
The simpliest case is when component was changed inside the builder. The backend simply republishes the file on CDN, so
|
|
306
|
+
the changes are visible the next time page is reloaded. If the previous version of the component file was cached in the
|
|
307
|
+
browser, the Clientside code will check if version of CDN file is more recent than the cached one, and will forcefully
|
|
308
|
+
reload the file and re-render it. The caching is implemented using a custom variation of stale-while-invalidate strategy
|
|
309
|
+
found in service workers. The difference is that the rendered cached component gets swapped upon recieving update
|
|
310
|
+
ensuring that there's no latency penalty to be paid for cache busting.
|
|
311
|
+
|
|
312
|
+
In case of builder publishing the changed component, all instances of that component on all sites and pages will see the
|
|
313
|
+
change, with exception of "forked" components (see below).
|
|
314
|
+
|
|
315
|
+
### Editing in place
|
|
316
|
+
|
|
317
|
+
At the time of embedding a component may be assigned a special instance attribute which determines unique identifier of
|
|
318
|
+
embedded component instance. That allows that component to be editable in place. Initially it will share its version
|
|
319
|
+
content, styles and settings with all the other instances of the same component. However after embedding user may decide
|
|
320
|
+
to edit the contents, styles or datasources of the component instance using an inline version of Component Builder
|
|
321
|
+
(inside Pages or on the website).
|
|
322
|
+
|
|
323
|
+
Further changes to the original component (staged or published) will stop affecting such edited component instance.
|
|
324
|
+
Change history of a that component instance becomes divergent from the history of the original, creating a metaphorical
|
|
325
|
+
fork in the road for the component. Editing component instance inline "forks" it.
|
|
326
|
+
|
|
327
|
+
A forked version of a component has simplified publishing flow: Changes to the forked component automatically become
|
|
328
|
+
visible in Pages and on the website (as if they were both staged and published). After initial integration, this will be
|
|
329
|
+
improved to make forked component a subject to Pages publishing lifecycle, acting exactly as other XM/SXA component
|
|
330
|
+
would.
|
|
331
|
+
|
|
332
|
+
It is possible to "unfork" component, resetting its changes and reverting to the shared state. It will both reset the
|
|
333
|
+
state, and will re-enable component receieve updates when the original is updated.
|
|
334
|
+
|
|
335
|
+
Technical difficulty of forking components lies in the hard requirement of being able to do forking and unforking
|
|
336
|
+
without the need for changing the embed code/configuration. Which makes the most intuitive sense in the use case of
|
|
337
|
+
editing component on the final HTML page, that lacks the mechanisms to communicate with backend to save the changes. It
|
|
338
|
+
could be that the component is even used in the context of static HTML that does not have any underlying CMS, so
|
|
339
|
+
changing the embedding code would require updating the remote file or template (perhaps even requiring a full release of
|
|
340
|
+
the app).
|
|
341
|
+
|
|
342
|
+
When the component is displayed on the page, it needs to fetch its HTML contents fron CDN. HTML files are put on the CDN
|
|
343
|
+
using predictable name, like: /components/:component_id/:version_id/:status.html. If a component has instance attribute
|
|
344
|
+
set, the clientside code will fetch a second url from CDN in parallel: /instances/:instance.html, thus determining if
|
|
345
|
+
that instance of a component was forked or not.
|
|
346
|
+
|
|
347
|
+
If the second request had 404 Not Found status, the original component definition returned by the first request would be
|
|
348
|
+
displayed. In that case the instance is considered not forked, so any staged/published changes to that component will be
|
|
349
|
+
reflected as usual.
|
|
350
|
+
|
|
351
|
+
If the second request was successful, then that forked version of a component will be displayed instead of the shared
|
|
352
|
+
one. Further updates to shared state will be shadowed by the customization until the component is unforked. But the
|
|
353
|
+
forked component remains editable.
|
|
354
|
+
|
|
355
|
+
### Versioning in UI
|
|
356
|
+
|
|
357
|
+
Bringing up the Editor on the forked component, displays Fork status instead of Draft. Staged and Published statuses can
|
|
358
|
+
be still previewed, showing the current upstream version of the component, allowing to visualize the changes that
|
|
359
|
+
happened to the original since forking. It will allow merging upstream changes to a fork, using CKEditor's operational
|
|
360
|
+
transformations feature. That requires computing diff of a fork against its original version, and then resolving it
|
|
361
|
+
against diff of upstream changes. OT ensures conflict-free merging of changes.
|
|
362
|
+
|
|
363
|
+
In addition to that, this same UI allows unforking, by reverting to either staged or published version.
|
|
364
|
+
|
|
365
|
+
### Swapping component
|
|
366
|
+
|
|
367
|
+
The most tricky case of in-line editing comes in case of swapping a component or version to another. Reference to the
|
|
368
|
+
component and the version is a part of embed code. In Pages we can simply update the component rendering parameters. But
|
|
369
|
+
for static HTML pages updating the embedding code is not an option.
|
|
370
|
+
|
|
371
|
+
Swapping a component in this case works as if instance of a component was forked, and its whole contents was replaced
|
|
372
|
+
with the contents of another component. The forked component HTML file on CDN, just like all other HTML files contains
|
|
373
|
+
metadata that indicate which component and version it relates to, thus allowing the UI to properly visualize upstream
|
|
374
|
+
staged/published states of the new component.
|
|
375
|
+
|
|
376
|
+
The limitation of this approach is that a swapped content will not reflect updates made to its definition. It could be
|
|
377
|
+
alleviated in the future by making yet another request to CDN to check for changes, but in the first implementation of
|
|
378
|
+
in-place editing this is not going to be addressed
|
|
379
|
+
|
|
380
|
+
# Component styling
|
|
381
|
+
|
|
382
|
+
Style guides is a tool for editing css stylesheets. It offers designers the ability to predefine reusable chunks of
|
|
383
|
+
style for individual elements and their compositions. The resulting styles are then packaged as a static CSS file
|
|
384
|
+
available for Component Builder, Page Builder, or regular HTML webpages.
|
|
385
|
+
|
|
386
|
+
Style guide can be invoked from within component builder too, allowing the builders to create one-off "instance" styles.
|
|
387
|
+
In that case the resulting style that is only applicable to a specific element, is placed directly into HTML document.
|
|
388
|
+
|
|
389
|
+
It is possible to use the styles as a part of BYOC component as well.
|
|
390
|
+
|
|
391
|
+
## Using elements and rules
|
|
392
|
+
|
|
393
|
+
Each element type like button, card, section has a dedicated class making it recieve the style. Designers can create
|
|
394
|
+
their own element types, but some are built in. FEAAS class name starts with dash.
|
|
395
|
+
|
|
396
|
+
- Text elements:
|
|
397
|
+
- `-paragraph` or `<p>`
|
|
398
|
+
- `-heading1` or `<h1>`
|
|
399
|
+
- `-heading2` or `<h2>`
|
|
400
|
+
- `-heading3` or `<h3>`
|
|
401
|
+
- `-heading4` or `<h4>`
|
|
402
|
+
- `-heading5` or `<h5>`
|
|
403
|
+
- `-heading6` or `<h6>`
|
|
404
|
+
- Block elements:
|
|
405
|
+
|
|
406
|
+
- `-card`
|
|
407
|
+
- `-section` or `<section>`
|
|
408
|
+
- `-blockquote` or `<blockquote>`
|
|
409
|
+
- `-block--media`
|
|
410
|
+
- `-block--my-custom-type` - custom block type
|
|
411
|
+
|
|
412
|
+
- Inline elements:
|
|
413
|
+
- `-button` or `<button>`
|
|
414
|
+
- `-link` or `<a>`
|
|
415
|
+
- `-inline--badge`
|
|
416
|
+
- `-inline--my-custom-type` - custom inline type
|
|
417
|
+
|
|
418
|
+
Applying the above classes inside an container with `-feaas -theme--name` classes will apply default theme styles for
|
|
419
|
+
each. It is possible to use specific element styles defined in style guides overriding theme defaults with extra
|
|
420
|
+
`--name` at the end:
|
|
421
|
+
|
|
422
|
+
`-button--primary` will apply `Primary` style of a button, and `-inline--badge--important` will apply `Important` style
|
|
423
|
+
of the badge
|
|
424
|
+
|
|
425
|
+
````HTML
|
|
426
|
+
|
|
427
|
+
<section class="-feaas -theme--default">
|
|
428
|
+
<!-- Button element with "Primary" style, overriding theme styles -->
|
|
429
|
+
<button class="-button--primary">
|
|
430
|
+
Default primary button
|
|
431
|
+
</button>
|
|
432
|
+
|
|
433
|
+
<!-- "Primary" button with "chunky-typography" override -->
|
|
434
|
+
<button class="-button--primary -typography--chunky">
|
|
435
|
+
Chunky primary button
|
|
436
|
+
</button>
|
|
437
|
+
|
|
438
|
+
<!--
|
|
439
|
+
"Primary" button with "instance" style created in builder.
|
|
440
|
+
Style is bundled inline as a part of the html output.
|
|
441
|
+
User can choose to start with reusable rule and "customize it".
|
|
442
|
+
In that case the instance style is linked with the original.
|
|
443
|
+
Removing the className belonging to instance style clears
|
|
444
|
+
up the instance style from the document. In this case, only t
|
|
445
|
+
he *typography* rule of the button was altered, so others
|
|
446
|
+
(like spacing or decoration) still retain the link to shared styles.
|
|
447
|
+
-->
|
|
448
|
+
<style>
|
|
449
|
+
.-typography--chunky[data-instance-id="unique"][class][class][class] {
|
|
450
|
+
font-size: 32px;
|
|
451
|
+
line-height: inherit;
|
|
452
|
+
/* ...goes on, lists all properties exhaustively
|
|
453
|
+
to completely override button's own default typography */
|
|
454
|
+
}
|
|
455
|
+
</style>
|
|
456
|
+
<button data-instance-id="unique" class="-button--primary -typography--chunky">
|
|
457
|
+
Customized chunky primary button
|
|
458
|
+
</button>
|
|
459
|
+
|
|
460
|
+
</section>
|
|
461
|
+
|
|
462
|
+
```
|
|
463
|
+
|
|
464
|
+
## Using themes
|
|
465
|
+
|
|
466
|
+
Style guides embraces controlled style cascade to allow parent elements to provide default styles for its children
|
|
467
|
+
elements. Children have flexibility to redefine any aspect of those inherited styles. [#Specificity-Layers] is used to
|
|
468
|
+
ensure styles do not clash.
|
|
469
|
+
|
|
470
|
+
Besides convenience of editing, this approach is essential to handle rich data mapping. HTML content coming from the CMS
|
|
471
|
+
needs to be styled "implicitly" through applying a theme to its parent element. This way paragraphs, headings, links and
|
|
472
|
+
pictures will have predictable styled look.
|
|
473
|
+
|
|
474
|
+
NOTE: composites feature is not yet exposed in the style guides UI.
|
|
475
|
+
|
|
476
|
+
It is also possible to specify theme styles. Supposed there's a theme button style with id `deadbeef`:
|
|
477
|
+
|
|
478
|
+
* `-feaas -theme--default -use--deadbeef` will make all buttons use that style inside the elementg
|
|
479
|
+
* `-button -deadbeef` - will make specific button use this style
|
|
480
|
+
|
|
481
|
+
```HTML
|
|
482
|
+
|
|
483
|
+
<section class="-feaas -theme--dark">
|
|
484
|
+
<div class="-section">
|
|
485
|
+
<!-- Card will pick up dark style from its theme -->
|
|
486
|
+
<div class="-card">
|
|
487
|
+
<div>
|
|
488
|
+
<!-- div element with default button styles as prescribed by theme -->
|
|
489
|
+
<div class="-button">
|
|
490
|
+
Yes
|
|
491
|
+
</div>
|
|
492
|
+
<!-- button with default styles as prescribed by theme -->
|
|
493
|
+
<button>
|
|
494
|
+
Yes
|
|
495
|
+
</button>
|
|
496
|
+
<!-- dark style button with only typography rule overriden -->
|
|
497
|
+
<button class="-typography--chunky">
|
|
498
|
+
No
|
|
499
|
+
</button>
|
|
500
|
+
</div>
|
|
501
|
+
|
|
502
|
+
<!-- static elements potentially coming from CMS via data mapping -->
|
|
503
|
+
<h2>Test<h2>
|
|
504
|
+
<p>Test<p>
|
|
505
|
+
<ul>
|
|
506
|
+
<li>Hey</li>
|
|
507
|
+
<li>Yo</li>
|
|
508
|
+
</ul>
|
|
509
|
+
<img src="..." />
|
|
510
|
+
<p>Test<p>
|
|
511
|
+
</div>
|
|
512
|
+
|
|
513
|
+
<!-- dark theme style for a card is overriden by buttons own style -->
|
|
514
|
+
<div class="-card--promo">
|
|
515
|
+
<!-- button is dark: not affected by card parent style override -->
|
|
516
|
+
<button></button>
|
|
517
|
+
</div>
|
|
518
|
+
|
|
519
|
+
|
|
520
|
+
<!-- FUTURE: theme applied to card, overriding dark theme of section -->
|
|
521
|
+
<div class="-card -theme--light -subtheme">
|
|
522
|
+
<!-- button is light: affected by card parent style override -->
|
|
523
|
+
<button></button>
|
|
524
|
+
</div>
|
|
525
|
+
|
|
526
|
+
<!-- composite elements have fully resolved class names -->
|
|
527
|
+
<div class="-block--accordion">
|
|
528
|
+
<!-- composite elements part are marked with
|
|
529
|
+
data-role attribute for easier handling of bubbled events -->
|
|
530
|
+
<button data-role="next">Forward</button>
|
|
531
|
+
<div data-role="list">
|
|
532
|
+
<div class="-card">
|
|
533
|
+
<img>
|
|
534
|
+
</div>
|
|
535
|
+
<div class="-card">
|
|
536
|
+
<img>
|
|
537
|
+
</div>
|
|
538
|
+
</div>
|
|
539
|
+
<button data-role="prev">Back</button>
|
|
540
|
+
</div>
|
|
541
|
+
</div>
|
|
542
|
+
</div>
|
|
543
|
+
|
|
544
|
+
````
|
|
545
|
+
|
|
546
|
+
## Advanced: Specificity layers
|
|
547
|
+
|
|
548
|
+
Style guides use limited cascading, and five levels of style hierarchy of styles (Resets, Themes, Elements, Rules and
|
|
549
|
+
Instance styles). In addition styles have to be order-independent to ensure the easiest integration with pages or apps.
|
|
550
|
+
These requirements call for very particular approach to selectors, in order for all styles to co-exist predictably.
|
|
551
|
+
|
|
552
|
+
Ideally this problem has to be solved through the use of Layers feature of CSS Level 4, but it's barely supported
|
|
553
|
+
anywhere. It is possible to emulate it for the needs of style guides, by spreading out each layers in specificity
|
|
554
|
+
values. To increase specificity of a selector, we employ repetition of `[class]` attribute selector. Below you can find
|
|
555
|
+
specs for all of the layers and the expected specificity values.
|
|
556
|
+
|
|
557
|
+
- Calculator: https://specificity.keegan.st/
|
|
558
|
+
- More info: https://developer.mozilla.org/en-US/docs/Web/CSS/Specificity
|
|
559
|
+
|
|
560
|
+
### CSS resets
|
|
561
|
+
|
|
562
|
+
Components need some basic styles reset in order to establish style baseline.
|
|
563
|
+
|
|
564
|
+
```CSS
|
|
565
|
+
/*
|
|
566
|
+
Resets: (0.1.0)
|
|
567
|
+
lowest priority
|
|
568
|
+
*/
|
|
569
|
+
[class*="-theme--"] * {
|
|
570
|
+
|
|
571
|
+
}
|
|
572
|
+
```
|
|
573
|
+
|
|
574
|
+
### Themes
|
|
575
|
+
|
|
576
|
+
Themes are composite styles that descend to the children. Children can then completely override them if necessary.
|
|
577
|
+
Themes are applied to the component root, or to a card if theme allows pairing
|
|
578
|
+
|
|
579
|
+
```CSS
|
|
580
|
+
/* Default styles for elements within a theme (1.1.1)(1.1.2)/(1.2.0)/(1.2.1)/(1.3.0) */
|
|
581
|
+
.-theme--cool:not(#_) h1 {}
|
|
582
|
+
.-theme--cool:not(#_) h1 a {}
|
|
583
|
+
.-theme--cool:not(#_) .-card {}
|
|
584
|
+
.-theme--cool:not(#_) .-block--accordion h1 {}
|
|
585
|
+
.-theme--cool:not(#_) .-block--accordion [role="accordion-button"] {}
|
|
586
|
+
|
|
587
|
+
/* Customized styles for elements within a theme (1.1.3)(1.1.4)/(1.2.2)/(1.2.3)/(1.3.2) */
|
|
588
|
+
.-use--deadbeef:not(#_):not(x):not(x) h1 {}
|
|
589
|
+
.-use--deadbeef:not(#_):not(x):not(x) h1 a{}
|
|
590
|
+
.-use--deadbeef:not(#_):not(x):not(x) .-card {}
|
|
591
|
+
.-use--deadbeef:not(#_):not(x):not(x) .-card h1 {}
|
|
592
|
+
.-use--deadbeef:not(#_):not(x):not(x):not(x):not(x) .-block--accordion [role="accordion-button"] {}
|
|
593
|
+
|
|
594
|
+
/* FUTURE: Nested theme override (1.2.4)/(1.2.5)/(1.3.3)/(1.3.4)/(1.4.3) */
|
|
595
|
+
.-theme--nested.-subtheme:not(x#_):not(x):not(x):not(x) h1 {}
|
|
596
|
+
.-theme--nested.-subtheme:not(x#_):not(x):not(x):not(x) h1 a {}
|
|
597
|
+
.-theme--nested.-subtheme:not(x#_):not(x):not(x):not(x) .-button {}
|
|
598
|
+
.-theme--nested.-subtheme:not(x#_):not(x):not(x):not(x) .-button h1 {}
|
|
599
|
+
.-theme--nested.-subtheme:not(x#_):not(x):not(x):not(x) .-block--accordion [role="accordion-button"] {}
|
|
600
|
+
```
|
|
601
|
+
|
|
602
|
+
### Elements
|
|
603
|
+
|
|
604
|
+
Elements are created with a choice of default reusable rules (typography, decoration, spacing, etc.). All styles are
|
|
605
|
+
merged together into a single definition of element class, allowing other reusable rules applied on top to override the
|
|
606
|
+
defaults. So only a single class needs to be applied for all default styles to take effect.
|
|
607
|
+
|
|
608
|
+
One benefit of that approach is that the designers may change the defaults for elements retroactively. For example, they
|
|
609
|
+
may change "Primary button" to have "Bold typography" by default. This take effect in all places where that button style
|
|
610
|
+
is used and which dont have typography rule override.
|
|
611
|
+
|
|
612
|
+
Some elements consist of parts (carousel has buttons, accordion has title & details, etc). Creating a style for
|
|
613
|
+
composite element is similar to theme, it adds default choice of buttons and styles. Later user can change an element
|
|
614
|
+
style, or only an aspect of it.
|
|
615
|
+
|
|
616
|
+
```CSS
|
|
617
|
+
|
|
618
|
+
/* Explicit element styles (1.5.0)/(1.6.0) */
|
|
619
|
+
.-card--cool:not(#_._._._._) {}
|
|
620
|
+
.-card--cool:not(#_._._._._) [data-role="prev"] {}
|
|
621
|
+
/* Explicit combo styles (1.5.1)/(1.6.1) */
|
|
622
|
+
.-theme--dark .-card--cool.--deadbeef:not(x#_._._) {}
|
|
623
|
+
.-theme--dark .-card--cool.--deadbeef:not(x#_._._) [role="accordion-button"] {}
|
|
624
|
+
/* Reusable rules need to override theme & element styles (1.7.0) */
|
|
625
|
+
.-typography--rule:not(#_._._._._._._) {}
|
|
626
|
+
.-typography--rule:not(#_._._._._._._)[data-instance-id="unique-element"] {}
|
|
627
|
+
```
|
|
628
|
+
|
|
629
|
+
#### Reusable rules
|
|
630
|
+
|
|
631
|
+
Reusable rules represent different aspects of styling: Typography, decoration, fill, etc. Creating element consists of
|
|
632
|
+
choosing applicable and default rules. Allowing more than one rule per category for an element, makes it possible for
|
|
633
|
+
designer to choose alternatives when placing that element on a page or component.
|
|
634
|
+
|
|
635
|
+
```CSS
|
|
636
|
+
/* Reusable rules need to override theme & element styles (1.7.0)/(1.8.0) */
|
|
637
|
+
.-typography--rule:not(#_._._._._._._) {}
|
|
638
|
+
.-typography--rule:not(#_._._._._._._)[data-instance-id="unique-element"] {}
|
|
639
|
+
```
|
|
640
|
+
|
|
641
|
+
## Properties
|
|
642
|
+
|
|
643
|
+
Style guides are meant to simplify the CSS creation, instead of being simply visual way to edit css. To remove
|
|
644
|
+
redundancy or complexity certain changes or additions had to be done:
|
|
645
|
+
|
|
646
|
+
### Spacing
|
|
647
|
+
|
|
648
|
+
Margins are pretty tricky in CSS (issues like margin-collapsing or auto value, and redundancy with padding can be
|
|
649
|
+
confusing). Style guides offer no direct manipilation of margin, and instead offer simplier options, either layout gap,
|
|
650
|
+
or paragraph spacing. To achieve that, the system uses a shared
|
|
651
|
+
[https://css-tricks.com/using-custom-property-stacks-to-tame-the-cascade/](variable stack) to ensure that value
|
|
652
|
+
customizations and redefinitions do not rely on specificity.
|
|
653
|
+
|
|
654
|
+
```CSS
|
|
655
|
+
/* Specificity does not matter for these definitions */
|
|
656
|
+
.element {
|
|
657
|
+
marign-top: var(---typography--paragraph-spacing, var(---self--row-gap, 0px));
|
|
658
|
+
marign-left: var(---self--column-gap, 0px);
|
|
659
|
+
}
|
|
660
|
+
```
|
|
661
|
+
|
|
662
|
+
- **Gap** - Space between elements in layout (columns, block elements), defined on the parent to control spacing between
|
|
663
|
+
its children.
|
|
664
|
+
|
|
665
|
+
```CSS
|
|
666
|
+
/* Specificity increase only affects variable assignment */
|
|
667
|
+
.-layout--horizontal:not(#_._._._._._._) > :nth-child(1n+3) {
|
|
668
|
+
---spacing--row-gap: 10px;
|
|
669
|
+
}
|
|
670
|
+
```
|
|
671
|
+
|
|
672
|
+
- **Gap override** (codename) - Child element can override the gap set by its parent. Used in builder. Similar to _
|
|
673
|
+
align-self_ and _justify-self_ logic of flexbox. Independent from direction of layout.
|
|
674
|
+
```CSS
|
|
675
|
+
/* Even though element style has lower priority than layout rule,
|
|
676
|
+
the ---self-- family of variables can be redefined on element itself */
|
|
677
|
+
.-card--my-element:not(x#_._._._._) {
|
|
678
|
+
---self--row-gap: 10px;
|
|
679
|
+
---self--column-gap: 10px;
|
|
680
|
+
}
|
|
681
|
+
```
|
|
682
|
+
- **Paragraph spacing** - like gap, but for text elements. Takes precedence over vertical gap. Because text elements can
|
|
683
|
+
not be direct children inside horizontal layouts, does not care about direction.
|
|
684
|
+
|
|
685
|
+
```CSS
|
|
686
|
+
/* Specificity is not important here, as the variable is not inherited*/
|
|
687
|
+
.element {
|
|
688
|
+
---typography--paragraph-spacing: 10px;
|
|
689
|
+
}
|
|
690
|
+
|
|
691
|
+
```
|
|
692
|
+
|
|
693
|
+
> > > > > > > Stashed changes
|