This repository has been archived by the owner on May 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7a3917b
commit 507cea3
Showing
137 changed files
with
3,502 additions
and
2,770 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
const scopeUsage = require('./scope-usage') | ||
const namedIndex = require('./named-index') | ||
|
||
module.exports = scopeUsage | ||
module.exports = namedIndex |
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,56 @@ | ||
import fs from 'fs' | ||
import path from 'path' | ||
|
||
const transformer = (file, api) => { | ||
const j = api.jscodeshift | ||
|
||
if (file.path.includes('index.js')) { | ||
let defaultDeclaration | ||
let namedDeclarations = [] | ||
|
||
const source = j(file.source) | ||
|
||
/* default declaration */ | ||
const defaults = source.find(j.ExportDefaultDeclaration) | ||
defaults.forEach(path => { | ||
defaultDeclaration = path.value.declaration.name | ||
}) | ||
|
||
/* named declarations */ | ||
const statements = [] | ||
source.find(j.ExportNamedDeclaration).forEach(path => statements.push(path.value.specifiers)) | ||
statements.forEach(statement => | ||
statement.forEach(specifier => namedDeclarations.push(specifier.local.name)) | ||
) | ||
|
||
/* rename index.js to component-name.js */ | ||
const directory = path.dirname(file.path) | ||
const component = directory.split('/').pop() | ||
|
||
fs.renameSync(file.path, file.path.replace('index', component)) | ||
|
||
/* write new file */ | ||
let code = `import ` | ||
if (defaultDeclaration) code += `${defaultDeclaration}` | ||
|
||
if (namedDeclarations.length) { | ||
if (defaultDeclaration) code += ', ' | ||
code += `{ ${namedDeclarations.join()} }` | ||
} | ||
code += ` from './${component}'` | ||
|
||
code += `\n\n` | ||
|
||
if (defaultDeclaration) code += `export default ${defaultDeclaration}` | ||
if (namedDeclarations.length) { | ||
code += `\n` | ||
code += `export { ${namedDeclarations.join()} }` | ||
} | ||
|
||
return code | ||
} | ||
|
||
return j(file.source).toSource() | ||
} | ||
|
||
export default transformer |
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 |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* | ||
This is a demo component to show how to write a good component. | ||
We will create a square box component here. | ||
There are 5 steps to do this | ||
*/ | ||
|
||
/* | ||
Step 1: Import all the dependencies | ||
- import React and styled-components, thes are the bread and butter | ||
- import prop type for documentation and validation | ||
- import tokens instead of hard coding values | ||
*/ | ||
|
||
import React from 'react' | ||
import styled from 'styled-components' | ||
import PropTypes from 'prop-types' | ||
|
||
import { colors, misc } from '@auth0/cosmos-tokens' | ||
|
||
/* | ||
Step 2: Create a styled element with css | ||
You can get the html element from styled.element like styled.a | ||
*/ | ||
|
||
const StyledBox = styled.div` | ||
/* all your css goes here */ | ||
/* you can use variables here like tokens */ | ||
background: ${colors.base.grayLightest}; | ||
border: 1px solid ${colors.base.grayDark}; | ||
border-radius: ${misc.radius}; | ||
/* you can use props here to customize the element */ | ||
width: ${props => (props.big ? '100px' : '50px')}; | ||
height: ${props => (props.big ? '100px' : '50px')}; | ||
/* this is how you add pseudo states */ | ||
&:hover { | ||
background: ${colors.base.grayLight}; | ||
} | ||
` | ||
|
||
/* | ||
* Step 3: Create a React component that returns the styled element, | ||
* Add description above the component, this will be shown in the docs | ||
*/ | ||
|
||
const Box = props => { | ||
/* you can pass on all the props to the component like this */ | ||
return <StyledBox {...props} /> | ||
} | ||
|
||
/* | ||
Step 4: We need to add prop information for our component | ||
- Add propTypes to make for documentation and validation | ||
- Add defaultProps for documentation | ||
*/ | ||
Box.propTypes = { | ||
/** This comment will be picked up by the docs */ | ||
big: PropTypes.bool | ||
} | ||
|
||
Box.defaultProps = { | ||
big: false | ||
} | ||
|
||
/* Finally, export the component */ | ||
export default Box | ||
|
||
/* | ||
We are not done yet, there is one more step to make our component usable | ||
Document the examples in _box.md | ||
*/ | ||
|
||
/* | ||
Bonus step: Add your component to component/index.js | ||
so that it can be imported from accross the system | ||
import { Box } from 'src/components' | ||
This is a step only for convenience while developing the system, | ||
it will be replaced with a more explicit syntax | ||
import { Box } from '@auth0/cosmos' | ||
*/ |
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,86 +1,3 @@ | ||
/* | ||
This is a demo component to show how to write a good component. | ||
We will create a square box component here. | ||
import Box from './_box' | ||
|
||
There are 5 steps to do this | ||
*/ | ||
|
||
/* | ||
Step 1: Import all the dependencies | ||
- import React and styled-components, thes are the bread and butter | ||
- import prop type for documentation and validation | ||
- import tokens instead of hard coding values | ||
*/ | ||
|
||
import React from 'react' | ||
import styled from 'styled-components' | ||
import PropTypes from 'prop-types' | ||
|
||
import { colors, misc } from '@auth0/cosmos-tokens' | ||
|
||
/* | ||
Step 2: Create a styled element with css | ||
You can get the html element from styled.element like styled.a | ||
*/ | ||
|
||
const StyledBox = styled.div` | ||
/* all your css goes here */ | ||
/* you can use variables here like tokens */ | ||
background: ${colors.base.grayLightest}; | ||
border: 1px solid ${colors.base.grayDark}; | ||
border-radius: ${misc.radius}; | ||
/* you can use props here to customize the element */ | ||
width: ${props => (props.big ? '100px' : '50px')}; | ||
height: ${props => (props.big ? '100px' : '50px')}; | ||
/* this is how you add pseudo states */ | ||
&:hover { | ||
background: ${colors.base.grayLight}; | ||
} | ||
` | ||
|
||
/* | ||
* Step 3: Create a React component that returns the styled element, | ||
* Add description above the component, this will be shown in the docs | ||
*/ | ||
|
||
const Box = props => { | ||
/* you can pass on all the props to the component like this */ | ||
return <StyledBox {...props} /> | ||
} | ||
|
||
/* | ||
Step 4: We need to add prop information for our component | ||
- Add propTypes to make for documentation and validation | ||
- Add defaultProps for documentation | ||
*/ | ||
Box.propTypes = { | ||
/** This comment will be picked up by the docs */ | ||
big: PropTypes.bool | ||
} | ||
|
||
Box.defaultProps = { | ||
big: false | ||
} | ||
|
||
/* Finally, export the component */ | ||
export default Box | ||
|
||
/* | ||
We are not done yet, there is one more step to make our component usable | ||
Document the examples in _box.md | ||
*/ | ||
|
||
/* | ||
Bonus step: Add your component to component/index.js | ||
so that it can be imported from accross the system | ||
import { Box } from 'src/components' | ||
This is a step only for convenience while developing the system, | ||
it will be replaced with a more explicit syntax | ||
import { Box } from '@auth0/cosmos' | ||
*/ |
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,65 @@ | ||
import styled from 'styled-components' | ||
|
||
import { colors, fonts, spacing, misc } from '@auth0/cosmos-tokens' | ||
|
||
const config = { | ||
basic: { | ||
background: colors.input.background, | ||
border: colors.input.border, | ||
hoverBorder: colors.input.borderHover, | ||
focusBorder: colors.input.borderFocus, | ||
placeholder: colors.input.placeholder | ||
}, | ||
readOnly: { | ||
background: colors.input.backgroundReadOnly, | ||
border: colors.input.border, | ||
hoverBorder: colors.input.border, | ||
focusBorder: colors.input.border, | ||
placeholder: colors.input.placeholderReadOnly | ||
}, | ||
error: { | ||
background: colors.input.background, | ||
border: colors.input.borderError, | ||
hoverBorder: colors.input.borderError, | ||
focusBorder: colors.input.borderError | ||
} | ||
} | ||
|
||
const getAttributes = props => { | ||
if (props.readOnly) return config.readOnly | ||
else if (props.error) return config.error | ||
else return config.basic | ||
} | ||
|
||
const StyledInput = styled.input` | ||
width: 100%; | ||
box-sizing: border-box; | ||
background: ${props => getAttributes(props).background}; | ||
border: 1px solid; | ||
border-color: ${props => getAttributes(props).border}; | ||
border-radius: ${misc.radius}; | ||
font-family: ${props => (props.code ? fonts.family.code : 'inherit')}; | ||
font-size: ${props => (props.code ? '13px' : 'inherit')}; | ||
color: ${colors.text.inputs}; | ||
padding: ${misc.inputs.padding} ${spacing.small}; | ||
cursor: ${props => (props.readOnly ? 'not-allowed' : 'auto')}; | ||
transition: border-color ${misc.animationDuration}, box-shadow ${misc.animationDuration}; | ||
&:hover { | ||
border-color: ${props => getAttributes(props).hoverBorder}; | ||
} | ||
&:focus { | ||
border-color: ${props => getAttributes(props).focusBorder}; | ||
box-shadow: 0px 0px 0 1px ${props => getAttributes(props).focusBorder}; | ||
outline: none; | ||
} | ||
&::-webkit-input-placeholder { | ||
color: ${props => getAttributes(props).placeholder}; | ||
} | ||
` | ||
|
||
export { StyledInput } |
Oops, something went wrong.