-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: replace emotion valid props with own solution
- Loading branch information
Showing
7 changed files
with
60 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import htmlAttributes from 'html-attributes'; | ||
import svgAttributes from 'svg-attributes'; | ||
|
||
const reactAttributes = { | ||
autoFocus: true, | ||
children: true, | ||
dangerouslySetInnerHTML: true, | ||
defaultChecked: true, | ||
defaultValue: true, | ||
innerHTML: true, | ||
key: true, | ||
ref: true, | ||
suppressContentEditableWarning: true, | ||
suppressHydrationWarning: true, | ||
valueLink: true, | ||
}; | ||
|
||
export const ATTRIBUTES = Object.assign({}, htmlAttributes, reactAttributes, svgAttributes); |
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,8 @@ | ||
import { ATTRIBUTES } from '@src/store/attributes'; | ||
|
||
export default function isValidProp(prop: string) { | ||
const isDOMAttribute = !!ATTRIBUTES[prop]; | ||
const isEventDataAriaProp = /^(([Aa][Rr][Ii][Aa]|[Dd][Aa][Tt][Aa])-.+)|(on[A-Z])/.test(prop); | ||
|
||
return isDOMAttribute || isEventDataAriaProp; | ||
} |
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,15 @@ | ||
import isValidProp from '@src/utils/isValidProp'; | ||
|
||
describe('utils/isValidProp', () => { | ||
it('should return true for valid DOM/React props', () => { | ||
const props = ['aria-label', 'data-key', 'className', 'children', 'onClick']; | ||
|
||
props.forEach((prop) => expect(isValidProp(prop)).toBe(true)); | ||
}); | ||
|
||
it('should return false for invalid DOM/React props', () => { | ||
const props = ['isPrimary', 'hasBorder', 'withTextColor']; | ||
|
||
props.forEach((prop) => expect(isValidProp(prop)).toBe(false)); | ||
}); | ||
}); |
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