-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: Add templates to try-it-out page (#63)
* docs: Add templates to try-it-out page * register only once * fix type check * pr suggestions * remove path-browserify * add @types/webpack-env * use paths instead of nodes * remove app.js filtering * Update apps/website/src/components/Playground/index.tsx Co-authored-by: Oleksandr Fediashov <[email protected]> Co-authored-by: Oleksandr Fediashov <[email protected]>
- Loading branch information
1 parent
69f7a31
commit 73cb7ef
Showing
19 changed files
with
296 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 8 additions & 2 deletions
10
apps/website/docs/try-it-out.mdx → apps/website/docs/try-it-out/try-it-out.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,17 @@ | ||
import Playground from '../src/components/Playground'; | ||
--- | ||
displayed_sidebar: tryItOutSidebar | ||
sidebar_position: 1 | ||
--- | ||
|
||
import Playground from '../../src/components/Playground'; | ||
|
||
# Try it out | ||
|
||
Don't know how to get started writing styles in Griffel ? | ||
|
||
Having trouble getting your styles to work the way you want to ? | ||
|
||
Use the editor below to try it out! Griffel on the left, CSS on the right. | ||
Use the editor below to try it out! Griffel on the left, CSS on the right. There are a collection | ||
of templates on the sidebar to get you started. | ||
|
||
<Playground /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,56 @@ | ||
// @ts-check | ||
const path = require('path'); | ||
const fs = require('fs'); | ||
const babel = require('@babel/core'); | ||
|
||
function generateTryItOutSidebar() { | ||
const playgroundTemplatePath = path.join(__dirname, '/src/components/Playground/code/templates'); | ||
const templateFiles = fs.readdirSync(playgroundTemplatePath); | ||
return templateFiles | ||
.map(templateFile => { | ||
const id = path.parse(templateFile).name; | ||
const templatePath = path.join(playgroundTemplatePath, templateFile); | ||
const code = fs.readFileSync(templatePath, { encoding: 'utf-8' }); | ||
const res = babel.parseSync(code, { filename: templateFile }); | ||
const meta = { name: id }; | ||
babel.traverse(res, { | ||
VariableDeclarator(path) { | ||
const idPath = path.get('id'); | ||
const initPath = path.get('init'); | ||
|
||
if (idPath.isIdentifier({ name: 'meta' }) && initPath.isObjectExpression) { | ||
const properties = initPath.get('properties'); | ||
if (Array.isArray(properties)) { | ||
properties.forEach(propertyPath => { | ||
if (propertyPath.isObjectProperty()) { | ||
const keyPath = propertyPath.get('key'); | ||
const valuePath = propertyPath.get('value'); | ||
|
||
if (keyPath.isIdentifier() && (valuePath.isStringLiteral() || valuePath.isBooleanLiteral())) { | ||
meta[keyPath.node.name] = valuePath.node.value; | ||
} | ||
} | ||
}); | ||
} | ||
} | ||
}, | ||
}); | ||
|
||
/** @type { {type: 'link'; label: string; href: string }} */ | ||
const sidebarItem = { | ||
type: 'link', | ||
label: meta.name, | ||
href: `/try-it-out#${id}`, | ||
}; | ||
|
||
return sidebarItem; | ||
}) | ||
.filter(Boolean); | ||
} | ||
|
||
/** @type {import('@docusaurus/plugin-content-docs').SidebarsConfig} */ | ||
const sidebars = { | ||
reactSidebar: [{ type: 'autogenerated', dirName: 'react' }], | ||
tryItOutSidebar: generateTryItOutSidebar(), | ||
}; | ||
|
||
module.exports = sidebars; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
20 changes: 20 additions & 0 deletions
20
apps/website/src/components/Playground/code/templates/border.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { makeStyles, shorthands } from '@griffel/core'; | ||
|
||
export default makeStyles({ | ||
border: { | ||
...shorthands.border('1px', 'solid', 'red'), | ||
}, | ||
borderTop: { | ||
...shorthands.borderTop('2px', 'solid', 'blue'), | ||
}, | ||
borderColor: { | ||
...shorthands.borderColor('red'), | ||
}, | ||
borderRadius: { | ||
...shorthands.borderRadius('5px'), | ||
}, | ||
}); | ||
|
||
export const meta = { | ||
name: 'Border', | ||
}; |
13 changes: 13 additions & 0 deletions
13
apps/website/src/components/Playground/code/templates/global.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { makeStyles, shorthands } from '@griffel/core'; | ||
|
||
export default makeStyles({ | ||
global: { | ||
':global([data-global-style])': { | ||
...shorthands.border('1px', 'solid'), | ||
}, | ||
}, | ||
}); | ||
|
||
export const meta = { | ||
name: 'Global styles', | ||
}; |
22 changes: 22 additions & 0 deletions
22
apps/website/src/components/Playground/code/templates/margin.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { makeStyles, shorthands } from '@griffel/core'; | ||
|
||
export default makeStyles({ | ||
one: { | ||
...shorthands.margin('1px'), | ||
}, | ||
two: { | ||
...shorthands.margin('2px', '2px'), | ||
}, | ||
|
||
three: { | ||
...shorthands.margin('3px', '3px'), | ||
}, | ||
|
||
four: { | ||
...shorthands.margin('4px', '4px', '5px'), | ||
}, | ||
}); | ||
|
||
export const meta = { | ||
name: 'Margin', | ||
}; |
18 changes: 18 additions & 0 deletions
18
apps/website/src/components/Playground/code/templates/media.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { makeStyles, shorthands } from '@griffel/core'; | ||
|
||
export default makeStyles({ | ||
root: { | ||
'@media(forced-colors: active)': { | ||
...shorthands.borderColor('transparent'), | ||
}, | ||
|
||
'@media screen and (max-width: 468px)': { | ||
...shorthands.gap('1.5rem'), | ||
display: 'grid', | ||
}, | ||
}, | ||
}); | ||
|
||
export const meta = { | ||
name: 'Media queries', | ||
}; |
17 changes: 17 additions & 0 deletions
17
apps/website/src/components/Playground/code/templates/nested.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { makeStyles } from '@griffel/core'; | ||
|
||
export default makeStyles({ | ||
nested: { | ||
'& span': { | ||
'& .p': { | ||
':hover': { | ||
color: 'red', | ||
}, | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
export const meta = { | ||
name: 'Nested selectors', | ||
}; |
22 changes: 22 additions & 0 deletions
22
apps/website/src/components/Playground/code/templates/padding.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { makeStyles, shorthands } from '@griffel/core'; | ||
|
||
export default makeStyles({ | ||
one: { | ||
...shorthands.padding('1px'), | ||
}, | ||
two: { | ||
...shorthands.padding('2px', '2px'), | ||
}, | ||
|
||
three: { | ||
...shorthands.padding('3px', '3px'), | ||
}, | ||
|
||
four: { | ||
...shorthands.padding('4px', '4px', '5px'), | ||
}, | ||
}); | ||
|
||
export const meta = { | ||
name: 'Padding', | ||
}; |
22 changes: 22 additions & 0 deletions
22
apps/website/src/components/Playground/code/templates/pseudo-elements.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { makeStyles } from '@griffel/core'; | ||
|
||
export default makeStyles({ | ||
before: { | ||
':before': { | ||
content: '""', | ||
position: 'absolute', | ||
}, | ||
}, | ||
|
||
after: { | ||
':after': { | ||
color: 'red', | ||
content: '""', | ||
position: 'absolute', | ||
}, | ||
}, | ||
}); | ||
|
||
export const meta = { | ||
name: 'Pseudo-elements', | ||
}; |
25 changes: 25 additions & 0 deletions
25
apps/website/src/components/Playground/code/templates/pseudo-selectors.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { makeStyles } from '@griffel/core'; | ||
|
||
export default makeStyles({ | ||
focus: { | ||
':focus': { | ||
color: 'red', | ||
}, | ||
}, | ||
|
||
hover: { | ||
':hover': { | ||
color: 'red', | ||
}, | ||
}, | ||
|
||
active: { | ||
':active': { | ||
color: 'red', | ||
}, | ||
}, | ||
}); | ||
|
||
export const meta = { | ||
name: 'Pseudo-selectors', | ||
}; |
31 changes: 31 additions & 0 deletions
31
apps/website/src/components/Playground/code/templates/selectors.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { makeStyles } from '@griffel/core'; | ||
|
||
export default makeStyles({ | ||
element: { | ||
'& > span': { | ||
color: 'red', | ||
}, | ||
}, | ||
|
||
attribute: { | ||
'&[data-attribute]': { | ||
color: 'red', | ||
}, | ||
}, | ||
|
||
class: { | ||
'&. child-class': { | ||
color: 'red', | ||
}, | ||
}, | ||
|
||
childClass: { | ||
'&.my-class': { | ||
color: 'red', | ||
}, | ||
}, | ||
}); | ||
|
||
export const meta = { | ||
name: 'Selectors', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.