Skip to content

Commit

Permalink
refactor(bezier-codemod): adopt border-style property so that transfo…
Browse files Browse the repository at this point in the history
…rmed code is shorter
  • Loading branch information
yangwooseong committed Dec 12, 2023
1 parent 2a10dcf commit d112f31
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
import { getArrowFunctionsWithOneArgument } from '../utils/function.js'

const getBorderStyle = (borderCallExpression: CallExpression<ts.CallExpression>) => {
const thinkNess = borderCallExpression
const width = borderCallExpression
.getArguments()
.find(Node.isNumericLiteral)
?.getText()
Expand All @@ -22,41 +22,26 @@ const getBorderStyle = (borderCallExpression: CallExpression<ts.CallExpression>)
?.getText()
.slice(1, -1)

if (!color || !width) { return null }

const borderDirection = borderCallExpression
.getArguments()
.find(Node.isObjectLiteralExpression)

const hasTop = borderDirection?.getProperty('top')?.getText() !== 'top: false'
const hasRight = borderDirection?.getProperty('right')?.getText() !== 'right: false'
const hasBottom = borderDirection?.getProperty('bottom')?.getText() !== 'bottom: false'
const hasLeft = borderDirection?.getProperty('left')?.getText() !== 'left: false'
const hasBorders = ['top', 'right', 'bottom', 'left']
.map((value) => borderDirection?.getProperty(value)?.getText() !== `${value}: false`)

let borderStyle = ''
let hasAdded = false

if (!thinkNess || !color) { return null }

if (hasTop && hasRight && hasBottom && hasLeft) { borderStyle += `border: ${thinkNess}px solid var(--${color});\n` } else {
if (hasTop) {
if (hasAdded) { borderStyle += ' ' }
hasAdded = true
borderStyle += `border-top: ${thinkNess}px solid var(--${color});\n`
}
if (hasRight) {
if (hasAdded) { borderStyle += ' ' }
hasAdded = true
borderStyle += `border-right: ${thinkNess}px solid var(--${color});\n`
}
if (hasBottom) {
if (hasAdded) { borderStyle += ' ' }
hasAdded = true
borderStyle += `border-bottom: ${thinkNess}px solid var(--${color});\n`
}
if (hasLeft) {
if (hasAdded) { borderStyle += ' ' }
hasAdded = true
borderStyle += `border-left: ${thinkNess}px solid var(--${color});\n`
}
if (hasBorders.every((v => v))) {
borderStyle = `border: ${width}px solid var(--${color});\n`
} else {
borderStyle += `border-color: var(--${color});\n`
borderStyle += ` border-style: ${hasBorders
.map((hasBorder) => (hasBorder ? 'solid' : 'none'))
.join(' ')
};\n`
borderStyle += ` border-width: ${width}px;\n`
}

return borderStyle
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@

const Wrapper = styled.div`
border-bottom: 0.5px solid var(--bdr-black-light);
border-color: var(--bdr-black-light);
border-style: none none solid none;
border-width: 0.5px;
`

const Wrapper = styled.div`
border-top: 1px solid var(--bg-txt-black);
border-right: 1px solid var(--bg-txt-black);
border-left: 1px solid var(--bg-txt-black);
border-color: var(--bg-txt-black);
border-style: solid solid none solid;
border-width: 1px;
`

const Wrapper = styled.div`
Expand All @@ -21,6 +23,8 @@ const div = style.div`
${({ divider }) =>
divider &&
css`
border-bottom: 1px solid var(--bdr-black-light);
border-color: var(--bdr-black-light);
border-style: none none solid none;
border-width: 1px;
`}
`

0 comments on commit d112f31

Please sign in to comment.