Skip to content

Commit

Permalink
fix: add support to eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
omariosouto committed Dec 14, 2021
1 parent d544207 commit f20edbe
Show file tree
Hide file tree
Showing 17 changed files with 873 additions and 240 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
**/*.d.ts
40 changes: 40 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
module.exports = {
env: {
browser: true,
es2021: true,
},
extends: [
'plugin:react/recommended',
'airbnb',
'plugin:@typescript-eslint/recommended',
'plugin:prettier/recommended',
],
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaFeatures: {
jsx: true,
},
ecmaVersion: 13,
sourceType: 'module',
},
plugins: ['react', 'react-hooks', '@typescript-eslint', 'prettier'],
rules: {
'import/no-unresolved': 'error',
'import/prefer-default-export': 'off',
'react/jsx-filename-extension': [1, { extensions: ['.tsx'] }],
'react/jsx-props-no-spreading': 'off',
'react/function-component-definition': [
2,
{
namedComponents: 'function-declaration',
},
],
'no-shadow': 'off',
'@typescript-eslint/no-shadow': ['error'],
},
settings: {
'import/resolver': {
typescript: {},
},
},
};
4 changes: 4 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"singleQuote": true,
"editorconfig": true
}
2 changes: 1 addition & 1 deletion @types/styled-jsx.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ declare module 'react' {
jsx?: boolean;
global?: boolean;
}
}
}
2 changes: 1 addition & 1 deletion lib/components.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
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 { Text } from '@lib/components/text/text';
141 changes: 81 additions & 60 deletions lib/components/box/box.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,80 +5,101 @@ import { StyleSheet } from '@lib/core/stylesheet/stylesheet';

interface BoxProps {
as?: any;
children?: any;
children: any;
className?: string;
styleSheet?: StyleSheet;
ref?: Ref<any>;
ref: Ref<any>;
}
export const Box = React.forwardRef(({
as,
styleSheet: { focus, hover, srOnly, ...styleSheet },
...props
}: BoxProps, ref) => {
const Tag = as || 'div';
export const Box = React.forwardRef(
(
{
as,
styleSheet: { focus, hover, srOnly, ...styleSheet },
...props
}: BoxProps,
ref
) => {
const Tag = as || 'div';

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

Box.defaultProps = {
as: 'div',
styleSheet: {},
}
className: '',
};
12 changes: 3 additions & 9 deletions lib/components/provider/provider.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
import React from 'react';

interface ProviderProps {
theme: any;
children: any;
}
export const Provider = ({ theme, children }: ProviderProps) => {
return (
<>
{children}
</>
);
}
export function Provider({ children }: ProviderProps) {
return children;
}
13 changes: 5 additions & 8 deletions lib/components/text/text.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,17 @@ import { StyleSheet } from '@lib/core/stylesheet/stylesheet';
import { Box } from '@lib/components/box/box';

interface TextProps {
styleSheet: StyleSheet;
styleSheet?: StyleSheet;
children: React.ReactNode;
}

export function Text({ children, styleSheet }: TextProps) {
export function Text({ children, styleSheet }: TextProps): JSX.Element {
return (
<Box styleSheet={styleSheet}>
<span>
{children}
</span>
<span>{children}</span>
</Box>
)
);
}

Text.defaultProps = {
styleSheet: {},
}
};
12 changes: 6 additions & 6 deletions lib/core/breakpoints/breakpoints.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export enum Breakpoints {
xs = "Breakpoints.xs",
sm = "Breakpoints.sm",
md = "Breakpoints.md",
lg = "Breakpoints.lg",
xl = "Breakpoints.xl",
}
xs = 'Breakpoints.xs',
sm = 'Breakpoints.sm',
md = 'Breakpoints.md',
lg = 'Breakpoints.lg',
xl = 'Breakpoints.xl',
}
2 changes: 1 addition & 1 deletion lib/core/stylesheet/stylesheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ export interface StyleSheet {
margin?: ResponsiveProperty<number>;
focus?: any;
hover?: any;
}
}
Loading

1 comment on commit f20edbe

@vercel
Copy link

@vercel vercel bot commented on f20edbe Dec 14, 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.