-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add new border radii theme and reset all on components (#2448)
- Loading branch information
1 parent
968522c
commit a00df61
Showing
19 changed files
with
125 additions
and
152 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
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,21 +1,13 @@ | ||
import { CSSObject } from '@xstyled/styled-components' | ||
|
||
import { WuiTheme } from './types' | ||
|
||
export type ThemeCards = { | ||
default: CSSObject | ||
cover: CSSObject | ||
} | ||
|
||
export const getCards = (theme: WuiTheme): ThemeCards => { | ||
const { radii } = theme | ||
export const getCards = (): ThemeCards => { | ||
return { | ||
default: { | ||
overflow: 'hidden', | ||
}, | ||
cover: { | ||
borderTopLeftRadius: radii.sm, | ||
borderTopRightRadius: radii.sm, | ||
}, | ||
} | ||
} |
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,8 +1,20 @@ | ||
import { WuiTheme } from './types' | ||
|
||
export type ThemeRadii = { | ||
none: string | ||
sm: string | ||
md: string | ||
lg: string | ||
xl: string | ||
[key: number]: string | ||
} | ||
|
||
export const radii: ThemeRadii = { sm: '4px', md: '6px', lg: '10px' } | ||
export const getRadii = (theme: WuiTheme): ThemeRadii => { | ||
return { | ||
none: '0', | ||
sm: theme.toRem(2), | ||
md: theme.toRem(4), | ||
lg: theme.toRem(8), | ||
xl: theme.toRem(16), | ||
} | ||
} |
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
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 |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* eslint-disable no-console */ | ||
/* eslint-disable @typescript-eslint/no-var-requires */ | ||
// This script will help you to migrate to our new radii values | ||
// node ./scripts/upgrade-radii.js "../YOUR_PROJECT/src/**/**.{ts,tsx}" | ||
const fs = require('fs/promises') | ||
|
||
const glob = require('glob') | ||
|
||
// const pattern = 'src/**/**.*(ts|tsx)' | ||
const [pattern = ''] = process.argv.slice(2) | ||
|
||
const newRadiiValues = { | ||
2: 'sm', | ||
'2px': 'sm', | ||
4: 'md', | ||
'4px': 'md', | ||
8: 'lg', | ||
'8px': 'lg', | ||
16: 'xl', | ||
'16px': 'xl', | ||
} | ||
|
||
const getNewRadiiValue = value => newRadiiValues[value] || value | ||
const removeQuotes = value => value.replaceAll('{', '').replaceAll('}', '').replaceAll('"', '') | ||
const removeSemicolon = value => value.replace(';', '') | ||
|
||
const cleanJsxRadiiValue = prop => { | ||
const [key, value] = prop.split('=') | ||
const newValue = getNewRadiiValue(removeQuotes(value)) | ||
|
||
return `${key}="${newValue}"` | ||
} | ||
|
||
const cleanStyledRadiiValue = prop => { | ||
const [key, value] = prop.split(':') | ||
const newValue = getNewRadiiValue(removeSemicolon(value).trim()) | ||
|
||
return `${key}: ${newValue};` | ||
} | ||
|
||
const upgradeJsxRadii = content => { | ||
const regex = /borderRadius=(\{(2|4|8|16)}|"(2px|4px|8px|16px)")/gm | ||
|
||
if (regex.test(content)) { | ||
const newContent = content.replaceAll(regex, cleanJsxRadiiValue) | ||
return newContent | ||
} | ||
|
||
return content | ||
} | ||
|
||
const upgradeStyledRadii = content => { | ||
const regex = /(border-radius):( )(2|4|8|16);/gm | ||
|
||
if (regex.test(content)) { | ||
const newContent = content.replaceAll(regex, cleanStyledRadiiValue) | ||
return newContent | ||
} | ||
|
||
return content | ||
} | ||
|
||
glob(pattern, (error, matches) => { | ||
if (error) console.log('error', error) | ||
|
||
matches.forEach(async match => { | ||
const file = await fs.readFile(match) | ||
let content = file.toString() | ||
|
||
content = upgradeStyledRadii(content) | ||
content = upgradeJsxRadii(content) | ||
|
||
await fs.writeFile(match, content) | ||
}) | ||
|
||
console.log('done') | ||
}) |
Oops, something went wrong.