You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Adds support for GraphQL query variables and variant definition for the styleguide (#4)
* Adds support for variables and variant argument in GraphQL queries to extract different versions of the styles (theming)
* Updates examples with new variant option
* Updates README with examples and adds headings for better structure
Copy file name to clipboardexpand all lines: README.md
+37
Original file line number
Diff line number
Diff line change
@@ -278,6 +278,8 @@ This also means that you can reuse the same query by using different alias:
278
278
}
279
279
```
280
280
281
+
#### Using fragments
282
+
281
283
Because _This is just GraphQL™_, you can also create fragments that can then be included in other queries:
282
284
283
285
```js
@@ -307,6 +309,8 @@ const otherH1Styles = gql`
307
309
308
310
This is a powerful pattern that avoids lots of repetitions and allows for a bigger separation of concerns.
309
311
312
+
#### Defining custom unit
313
+
310
314
You can also override the pre-defined unit directly in your query by using the argument `unit`:
311
315
312
316
```js
@@ -322,6 +326,39 @@ You can also override the pre-defined unit directly in your query by using the a
322
326
323
327
This will return `marginLeft: 24em, paddingTop: 32px`.
324
328
329
+
#### Using style variations (theming)
330
+
331
+
One of the big advantages of CSS-in-GQL™ is that you can use the power of variables to build custom queries. In `graphql-css` that means that we can easily define variants (think themes) for specific components.
332
+
333
+
```js
334
+
conststyles= {
335
+
theme: {
336
+
light: {
337
+
button: {
338
+
// button light styles
339
+
},
340
+
},
341
+
dark: {
342
+
button: {
343
+
// button dark styles
344
+
},
345
+
},
346
+
},
347
+
};
348
+
349
+
conststateStyles=gql`
350
+
{
351
+
theme(variant: $variant) {
352
+
button
353
+
}
354
+
}
355
+
`;
356
+
357
+
// This can also be a stateful component that changes the variant according to state.
358
+
// Please check the examples folder for a detailed example.
0 commit comments