-
-
Notifications
You must be signed in to change notification settings - Fork 38
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
9c51ba6
commit 49a64ac
Showing
17 changed files
with
441 additions
and
139 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,126 @@ | ||
import React, { Ref } from 'react'; | ||
import { renderCSS } from '@lib/utils/renderCSS'; | ||
import { theme } from '@lib/core/theme/theme'; | ||
import { StyleSheet } from '@lib/core/stylesheet/stylesheet'; | ||
import { Breakpoints } from '@lib/core/breakpoints/breakpoints'; | ||
|
||
interface BoxProps { | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
as?: any; | ||
value?: string; | ||
children?: React.ReactNode; | ||
className?: string; | ||
styleSheet?: StyleSheet; | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
ref: Ref<any>; | ||
} | ||
|
||
export const BoxBase = React.forwardRef( | ||
( | ||
{ | ||
as, | ||
styleSheet: { focus, hover, disabled, srOnly, ...styleSheet }, | ||
...props | ||
}: BoxProps, | ||
ref | ||
) => { | ||
const Tag = as || 'div'; | ||
const selector = `sknui-${Tag.toLowerCase()}`; | ||
const jsxValue = process.env.NODE_ENV === 'test' ? 'true' : true; | ||
const className = `${selector} ${props.className ? props.className : ''} ${ | ||
srOnly ? 'sr-only' : '' | ||
}`.trim(); | ||
|
||
return ( | ||
<> | ||
<Tag ref={ref} {...props} className={className} /> | ||
<style jsx={jsxValue}>{` | ||
${`${Tag}.${selector}`} { | ||
${renderCSS(styleSheet, 'xs')}; | ||
} | ||
${`${Tag}.${selector}`}:hover:enabled { | ||
${renderCSS(hover, 'xs')}; | ||
} | ||
${`${Tag}.${selector}`}:focus:enabled { | ||
${renderCSS(focus, 'xs')}; | ||
} | ||
${`${Tag}.${selector}`}:disabled { | ||
${renderCSS(disabled, 'xs')}; | ||
} | ||
@media screen and (min-width: ${theme.breakpoints[ | ||
Breakpoints.sm | ||
]}px) { | ||
${`${Tag}.${selector}`} { | ||
${renderCSS(styleSheet, 'sm')}; | ||
} | ||
${`${Tag}.${selector}`}:hover:enabled { | ||
${renderCSS(hover, 'sm')}; | ||
} | ||
${`${Tag}.${selector}`}:focus:enabled { | ||
${renderCSS(focus, 'sm')}; | ||
} | ||
${`${Tag}.${selector}`}:disabled { | ||
${renderCSS(disabled, 'sm')}; | ||
} | ||
} | ||
@media screen and (min-width: ${theme.breakpoints[ | ||
Breakpoints.md | ||
]}px) { | ||
${`${Tag}.${selector}`} { | ||
${renderCSS(styleSheet, 'md')}; | ||
} | ||
${`${Tag}.${selector}`}:hover:enabled { | ||
${renderCSS(hover, 'md')}; | ||
} | ||
${`${Tag}.${selector}`}:focus:enabled { | ||
${renderCSS(focus, 'md')}; | ||
} | ||
${`${Tag}.${selector}`}:disabled { | ||
${renderCSS(disabled, 'md')}; | ||
} | ||
} | ||
@media screen and (min-width: ${theme.breakpoints[ | ||
Breakpoints.lg | ||
]}px) { | ||
${`${Tag}.${selector}`} { | ||
${renderCSS(styleSheet, 'lg')}; | ||
} | ||
${`${Tag}.${selector}`}:hover:enabled { | ||
${renderCSS(hover, 'lg')}; | ||
} | ||
${`${Tag}.${selector}`}:focus:enabled { | ||
${renderCSS(focus, 'lg')}; | ||
} | ||
${`${Tag}.${selector}`}:disabled { | ||
${renderCSS(disabled, 'lg')}; | ||
} | ||
} | ||
@media screen and (min-width: ${theme.breakpoints[ | ||
Breakpoints.xl | ||
]}px) { | ||
${`${Tag}.${selector}`} { | ||
${renderCSS(styleSheet, 'xl')}; | ||
} | ||
${`${Tag}.${selector}`}:hover:enabled { | ||
${renderCSS(hover, 'xl')}; | ||
} | ||
${`${Tag}.${selector}`}:focus:enabled { | ||
${renderCSS(focus, 'xl')}; | ||
} | ||
${`${Tag}.${selector}`}:disabled { | ||
${renderCSS(disabled, 'xl')}; | ||
} | ||
} | ||
`}</style> | ||
</> | ||
); | ||
} | ||
); | ||
|
||
BoxBase.defaultProps = { | ||
as: 'div', | ||
children: null, | ||
styleSheet: {}, | ||
value: '', | ||
className: '', | ||
}; |
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.
49a64ac
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs: