Skip to content

Commit

Permalink
feat: add initial components
Browse files Browse the repository at this point in the history
  • Loading branch information
omariosouto committed Dec 19, 2021
1 parent 9c51ba6 commit 49a64ac
Show file tree
Hide file tree
Showing 17 changed files with 441 additions and 139 deletions.
3 changes: 3 additions & 0 deletions lib/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@ export { theme } from '@lib/core/theme/theme';
export { Box } from '@lib/components/box/box';
export { Provider } from '@lib/components/provider/provider';
export { Text } from '@lib/components/text/text';
export { TextField } from '@lib/components/textfield/textfield';
export { Button } from '@lib/components/button/button';
export { Image } from '@lib/components/image/image';
48 changes: 32 additions & 16 deletions lib/components/box/__snapshots__/box.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -4,64 +4,80 @@ exports[`works 1`] = `
<div>
<main>
<div
class="sknui-box "
class="sknui-div"
value=""
>
Hello a
</div>
<style
jsx="true"
>
div.sknui-box {
div.sknui-div {
background-color:red;padding:10;;
}
div.sknui-box:hover {
div.sknui-div:hover:enabled {
;
}
div.sknui-box:focus {
div.sknui-div:focus:enabled {
;
}
div.sknui-div:disabled {
;
}
@media screen and (min-width: 480px) {
div.sknui-box {
div.sknui-div {
;
}
div.sknui-box:hover {
div.sknui-div:hover:enabled {
;
}
div.sknui-box:focus {
div.sknui-div:focus:enabled {
;
}
div.sknui-div:disabled {
;
}
}
@media screen and (min-width: 768px) {
div.sknui-box {
div.sknui-div {
;
}
div.sknui-div:hover:enabled {
;
}
div.sknui-box:hover {
div.sknui-div:focus:enabled {
;
}
div.sknui-box:focus {
div.sknui-div:disabled {
;
}
}
@media screen and (min-width: 992px) {
div.sknui-box {
div.sknui-div {
;
}
div.sknui-div:hover:enabled {
;
}
div.sknui-box:hover {
div.sknui-div:focus:enabled {
;
}
div.sknui-box:focus {
div.sknui-div:disabled {
;
}
}
@media screen and (min-width: 1200px) {
div.sknui-box {
div.sknui-div {
;
}
div.sknui-div:hover:enabled {
;
}
div.sknui-box:hover {
div.sknui-div:focus:enabled {
;
}
div.sknui-box:focus {
div.sknui-div:disabled {
;
}
}
Expand Down
126 changes: 126 additions & 0 deletions lib/components/box/box-base.tsx
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: '',
};
10 changes: 8 additions & 2 deletions lib/components/box/box.stories.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,14 @@ Box is the most primal component that we have that has the representation of a "
>
<Box
styleSheet={{
backgroundColor: 'red',
color: 'blue',
color: 'red',
backgroundColor: {
xs: 'red',
sm: 'blue',
md: 'green',
lg: 'purple',
xl: 'black',
},
}}
>
Box Component
Expand Down
4 changes: 2 additions & 2 deletions lib/components/box/box.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ it('works', () => {
<Box
styleSheet={{
backgroundColor: {
'Breakpoints.xs': 'red',
xs: 'red',
},
padding: {
'Breakpoints.xs': 10,
xs: 10,
},
}}
>
Expand Down
111 changes: 16 additions & 95 deletions lib/components/box/box.tsx
Original file line number Diff line number Diff line change
@@ -1,106 +1,27 @@
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 { BoxBase } from '@lib/components/box/box-base';

interface BoxProps {
as?: any;
children: any;
as?:
| 'form' // Prefer to use the <Form /> component instead.
| 'div'
| 'ul'
| 'main'
| 'section'
| 'article'
| 'header'
| 'footer'
| 'nav';
children: React.ReactNode;
className?: string;
styleSheet?: StyleSheet;
ref: Ref<any>;
ref: Ref<unknown>;
}

export const Box = React.forwardRef(
(
{
as,
styleSheet: { focus, hover, srOnly, ...styleSheet },
...props
}: BoxProps,
ref
) => {
console.log('Testing stuff');
const Tag = as || 'div';
const selector = 'sknui-box';
const jsxValue = process.env.NODE_ENV === 'test' ? 'true' : true;

return (
<>
<Tag
ref={ref}
{...props}
className={`sknui-box ${props.className ? props.className : ''} ${
srOnly ? 'sr-only' : ''
}`}
/>
<style jsx={jsxValue}>{`
${`${Tag}.${selector}`} {
${renderCSS(styleSheet, 'xs')};
}
${`${Tag}.${selector}`}:hover {
${renderCSS(hover, 'xs')};
}
${`${Tag}.${selector}`}:focus {
${renderCSS(focus, 'xs')};
}
@media screen and (min-width: ${theme.breakpoints[
'Breakpoints.sm'
]}px) {
${`${Tag}.${selector}`} {
${renderCSS(styleSheet, 'sm')};
}
${`${Tag}.${selector}`}:hover {
${renderCSS(hover, 'sm')};
}
${`${Tag}.${selector}`}:focus {
${renderCSS(focus, 'sm')};
}
}
@media screen and (min-width: ${theme.breakpoints[
'Breakpoints.md'
]}px) {
${`${Tag}.${selector}`} {
${renderCSS(styleSheet, 'md')};
}
${`${Tag}.${selector}`}:hover {
${renderCSS(hover, 'md')};
}
${`${Tag}.${selector}`}:focus {
${renderCSS(focus, 'md')};
}
}
@media screen and (min-width: ${theme.breakpoints[
'Breakpoints.lg'
]}px) {
${`${Tag}.${selector}`} {
${renderCSS(styleSheet, 'lg')};
}
${`${Tag}.${selector}`}:hover {
${renderCSS(hover, 'lg')};
}
${`${Tag}.${selector}`}:focus {
${renderCSS(focus, 'lg')};
}
}
@media screen and (min-width: ${theme.breakpoints[
'Breakpoints.xl'
]}px) {
${`${Tag}.${selector}`} {
${renderCSS(styleSheet, 'xl')};
}
${`${Tag}.${selector}`}:hover {
${renderCSS(hover, 'xl')};
}
${`${Tag}.${selector}`}:focus {
${renderCSS(focus, 'xl')};
}
}
`}</style>
</>
);
}
);
export const Box = React.forwardRef((props: BoxProps, ref) => {
return <BoxBase {...props} ref={ref} />;
});

Box.defaultProps = {
as: 'div',
Expand Down
Loading

1 comment on commit 49a64ac

@vercel
Copy link

@vercel vercel bot commented on 49a64ac Dec 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.