generated from morewings/react-library-template
-
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.
* WIP * add layout
- Loading branch information
Showing
21 changed files
with
755 additions
and
19 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,11 +1,11 @@ | ||
import {useState} from 'react'; | ||
|
||
const useLogic = (initialState: number) => { | ||
const [count, setCount] = useState(initialState); | ||
return { | ||
count, | ||
incrementCount: () => setCount(count + 1), | ||
}; | ||
const [count, setCount] = useState(initialState); | ||
return { | ||
count, | ||
incrementCount: () => setCount(count + 1), | ||
}; | ||
}; | ||
|
||
export default useLogic; |
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,12 @@ | ||
.cell { | ||
align-items: center; | ||
background: steelblue; | ||
border-radius: 4px; | ||
color: white; | ||
display: flex; | ||
flex-direction: column; | ||
height: 64px; | ||
justify-content: center; | ||
margin-bottom: 24px; | ||
width: 100%; | ||
} |
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,7 @@ | ||
import type {FC, ReactNode} from 'react'; | ||
|
||
import classes from './Cell.module.css'; | ||
|
||
export const Cell: FC<{children?: ReactNode}> = ({children}) => { | ||
return <div className={classes.cell}>{children}</div>; | ||
}; |
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,70 @@ | ||
import type {FC, ReactNode} from 'react'; | ||
import {useEffect} from 'react'; | ||
import {useLocalTheme} from 'css-vars-hook'; | ||
import classNames from 'classnames'; | ||
|
||
import type {OffsetConfig, SizesConfig} from './SizeTypes'; | ||
import classes from './Layout.module.css'; | ||
|
||
export type ColProps = Partial<SizesConfig> & | ||
Partial<OffsetConfig> & { | ||
/** Select an HTML element to render as a container */ | ||
as?: string; | ||
children?: ReactNode; | ||
className?: string; | ||
}; | ||
|
||
export const Col: FC<ColProps> = ({ | ||
as = 'div', | ||
children, | ||
className, | ||
xs, | ||
sm, | ||
md, | ||
lg, | ||
xl, | ||
offsetXS, | ||
offsetSM, | ||
offsetMD, | ||
offsetLG, | ||
offsetXL, | ||
}) => { | ||
const {LocalRoot, setTheme} = useLocalTheme(); | ||
|
||
useEffect(() => { | ||
setTheme({ | ||
xs: xs ?? '', | ||
sm: sm ?? '', | ||
md: md ?? '', | ||
lg: lg ?? '', | ||
xl: xl ?? '', | ||
offsetXS: offsetXS ?? '', | ||
offsetSM: offsetSM ?? '', | ||
offsetMD: offsetMD ?? '', | ||
offsetLG: offsetLG ?? '', | ||
offsetXL: offsetXL ?? '', | ||
}); | ||
}, [setTheme, xs, sm, md, lg, xl, offsetXS, offsetSM, offsetMD, offsetLG, offsetXL]); | ||
return ( | ||
<LocalRoot | ||
as={as} | ||
className={classNames( | ||
classes.column, | ||
{ | ||
[classes.xs]: !!xs, | ||
[classes.sm]: !!sm, | ||
[classes.md]: !!md, | ||
[classes.lg]: !!lg, | ||
[classes.xl]: !!xl, | ||
[classes['fluid-xs']]: xs === 'fluid', | ||
[classes['fluid-sm']]: sm === 'fluid', | ||
[classes['fluid-md']]: md === 'fluid', | ||
[classes['fluid-lg']]: lg === 'fluid', | ||
[classes['fluid-xl']]: xl === 'fluid', | ||
}, | ||
className | ||
)}> | ||
{children} | ||
</LocalRoot> | ||
); | ||
}; |
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,48 @@ | ||
import type {FC, ReactNode} from 'react'; | ||
import {useLocalTheme} from 'css-vars-hook'; | ||
import {useEffect} from 'react'; | ||
import classNames from 'classnames'; | ||
|
||
import type {SizeUnit, FluidUnit} from './SizeTypes'; | ||
import classes from './Layout.module.css'; | ||
|
||
export type ContainerProps = { | ||
/** Set Container width in pixels as a number or set to `fluid` to make it 100% */ | ||
containerWidth?: SizeUnit | FluidUnit; | ||
/** Set amount of columns to place in container */ | ||
base?: number; | ||
/** Set a gap between columns in pixels */ | ||
gap?: number; | ||
/** Select HTML element to render as a container */ | ||
as?: string; | ||
/** Specify additional CSS class. This allows you to use styled(Container) or the css prop in styled-components or emotion. */ | ||
className?: string; | ||
children: ReactNode; | ||
}; | ||
|
||
const normalizeWidth = (widthProp: ContainerProps['containerWidth']) => { | ||
if (widthProp === 'fluid') { | ||
return '100%'; | ||
} | ||
return `${widthProp}px`; | ||
}; | ||
|
||
export const Container: FC<ContainerProps> = ({ | ||
containerWidth = 1280, | ||
className, | ||
as = 'div', | ||
children, | ||
gap = 16, | ||
base = 12, | ||
}) => { | ||
const width = normalizeWidth(containerWidth); | ||
const {LocalRoot, setTheme} = useLocalTheme(); | ||
useEffect(() => { | ||
setTheme({containerWidth: width, base, gap: `${gap}px`}); | ||
}, [setTheme, width, gap, base]); | ||
return ( | ||
<LocalRoot as={as} className={classNames(classes.container, className)}> | ||
{children} | ||
</LocalRoot> | ||
); | ||
}; |
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,36 @@ | ||
import { Meta, ArgsTable, Story } from "@storybook/blocks"; | ||
import * as LayoutStories from './Layout.stories'; | ||
import { Container } from "./Container"; | ||
|
||
<Meta title="Layout/Container" component={Container} /> | ||
|
||
# Example Component Demo | ||
|
||
## Counter props | ||
|
||
<ArgsTable of={Container} /> | ||
|
||
## Description | ||
|
||
`Counter` component provides user basic interface to increment counter by one. | ||
|
||
## Demo | ||
|
||
<Story of={LayoutStories.ContainerExample} /> | ||
|
||
## Demo 2 | ||
|
||
<Story of={LayoutStories.ContainerResponsive} /> | ||
|
||
## Demo 3 | ||
|
||
<Story of={LayoutStories.ContainerOffset} /> | ||
|
||
## Demo 4 | ||
|
||
<Story of={LayoutStories.ContainerFluid} /> | ||
|
||
## Demo 4 | ||
|
||
<Story of={LayoutStories.ContainerWidth} /> | ||
|
Oops, something went wrong.