-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🔀 merge branch 'develop' into antoinekm/docs
- Loading branch information
Showing
6 changed files
with
296 additions
and
8 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,117 @@ | ||
import { Skeleton, Container, Button } from "@tonightpass/kitchen"; | ||
import { NextPage } from "next"; | ||
import React from "react"; | ||
import styled from "styled-components"; | ||
|
||
const SkeletonPage: NextPage = () => { | ||
return ( | ||
<> | ||
<Container | ||
gap={10} | ||
style={{ | ||
maxWidth: 700, | ||
margin: "0 auto", | ||
marginTop: "15px", | ||
}} | ||
> | ||
<p>default with set width</p> | ||
<Skeleton width={160} /> | ||
</Container> | ||
<Container | ||
gap={10} | ||
style={{ | ||
maxWidth: 700, | ||
margin: "0 auto", | ||
marginTop: "15px", | ||
}} | ||
> | ||
<p>default with box height</p> | ||
<Skeleton width={160} boxHeight={42} /> | ||
</Container> | ||
<Container | ||
gap={10} | ||
style={{ | ||
maxWidth: 700, | ||
margin: "0 auto", | ||
marginTop: "15px", | ||
}} | ||
> | ||
<p>wrapping children</p> | ||
<Skeleton> | ||
<TestButton>Hidden by skeleton</TestButton> | ||
</Skeleton> | ||
|
||
<Skeleton show={false}> | ||
<Button>Not hidden by skeleton</Button> | ||
</Skeleton> | ||
</Container> | ||
<Container | ||
gap={10} | ||
style={{ | ||
maxWidth: 700, | ||
margin: "0 auto", | ||
marginTop: "15px", | ||
}} | ||
> | ||
<p>wrapping children with fixed size</p> | ||
<Skeleton width="100%" height={100}> | ||
{null} | ||
</Skeleton> | ||
|
||
<Skeleton width="100%" height={100} show={false}> | ||
<TestButton width="200px">Not hidden by Skeleton</TestButton> | ||
</Skeleton> | ||
</Container> | ||
<Container | ||
gap={10} | ||
style={{ | ||
maxWidth: 700, | ||
margin: "0 auto", | ||
marginTop: "15px", | ||
}} | ||
> | ||
<p>normal</p> | ||
<Skeleton shape="normal" width={48} /> | ||
</Container> | ||
<Container | ||
gap={10} | ||
style={{ | ||
maxWidth: 700, | ||
margin: "0 auto", | ||
marginTop: "15px", | ||
}} | ||
> | ||
<p>round</p> | ||
<Skeleton shape="round" width={48} height={48} boxHeight={48} /> | ||
</Container> | ||
<Container | ||
gap={10} | ||
style={{ | ||
maxWidth: 700, | ||
margin: "0 auto", | ||
marginTop: "15px", | ||
}} | ||
> | ||
<p>square</p> | ||
<Skeleton shape="square" width={48} height={48} boxHeight={48} /> | ||
</Container> | ||
<Container | ||
gap={10} | ||
style={{ | ||
maxWidth: 700, | ||
margin: "0 auto", | ||
marginTop: "15px", | ||
}} | ||
> | ||
<p>no animation</p> | ||
<Skeleton width="100%" height={100} animated={false}> | ||
{null} | ||
</Skeleton> | ||
</Container> | ||
</> | ||
); | ||
}; | ||
|
||
const TestButton = styled(Button)``; | ||
|
||
export default SkeletonPage; |
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,159 @@ | ||
import React from "react"; | ||
import styled from "styled-components"; | ||
import { KitchenComponent } from "../../types"; | ||
import isString from "../../utils/isString"; | ||
|
||
export type SkeletonProps = KitchenComponent & { | ||
/** | ||
* The skeleton's appearance (if it's shown or not). | ||
*/ | ||
show?: boolean; | ||
|
||
/** | ||
* The skeleton's width. | ||
*/ | ||
width?: number | string; | ||
|
||
/** | ||
* The skeleton's height. | ||
*/ | ||
height?: number | string; | ||
|
||
/** | ||
* The skeleton's box height. | ||
*/ | ||
boxHeight?: number; | ||
|
||
/** | ||
* The skeleton's mode (animated or not). | ||
*/ | ||
animated?: boolean; | ||
|
||
/** | ||
* The skeleton's shape. | ||
*/ | ||
shape?: "normal" | "square" | "round"; | ||
|
||
/** | ||
* The skeleton's children. | ||
*/ | ||
children?: React.ReactNode; | ||
|
||
/** | ||
* The skeleton's key. | ||
*/ | ||
[key: string]: any; | ||
}; | ||
|
||
const Skeleton = styled( | ||
({ | ||
as: Component = "span", | ||
children, | ||
width, | ||
height, | ||
show = true, | ||
animated = true, | ||
...props | ||
}: SkeletonProps) => { | ||
if (!show && !children) return <></>; | ||
if (!show && children) return children as JSX.Element; | ||
return ( | ||
<Component | ||
width={width} | ||
height={height} | ||
show={show} | ||
animated={animated} | ||
{...props} | ||
> | ||
{children} | ||
</Component> | ||
); | ||
} | ||
)<SkeletonProps>` | ||
Skeleton.displayName = "Skeleton"; | ||
${({ children, show = true, width, height, shape, theme, animated = true }) => | ||
children | ||
? ` | ||
position: relative; | ||
display: block; | ||
width: ${width ? "100%" : "auto"}; | ||
max-width: ${ | ||
width ? (isString(width) ? width : `${width}px`) : "unset" | ||
}; | ||
min-height: ${ | ||
height ? (isString(height) ? height : `${height}px`) : "auto" | ||
}; | ||
${ | ||
show | ||
? ` | ||
::before { | ||
content: ""; | ||
position: absolute; | ||
top: 0; | ||
left: 0; | ||
right: 0; | ||
bottom: 0; | ||
z-index: 100; | ||
user-select: none; | ||
cursor: default; | ||
border-radius: ${ | ||
shape === "square" ? "0" : shape === "round" ? "99999px" : "8px" | ||
}; | ||
background-image: linear-gradient( | ||
270deg, | ||
${theme.colors.layout.darkest}, | ||
${theme.colors.layout.dark}, | ||
${theme.colors.layout.dark}, | ||
${theme.colors.layout.darkest} | ||
); | ||
background-size: 400% 100%; | ||
animation: ${ | ||
animated ? "skeleton 8s ease-in-out infinite" : "none" | ||
}; | ||
} | ||
` | ||
: "" | ||
} | ||
` | ||
: ` | ||
display: block; | ||
width: 100%; | ||
user-select: none; | ||
cursor: default; | ||
max-width: ${ | ||
width ? (isString(width) ? width : `${width}px`) : "24px" | ||
}; | ||
min-height: ${ | ||
height ? (isString(height) ? height : `${height}px`) : "24px" | ||
}; | ||
border-radius: ${ | ||
shape === "square" ? "0" : shape === "round" ? "99999px" : "8px" | ||
}; | ||
background-size: 400% 100%; | ||
background-image: linear-gradient( | ||
270deg, | ||
${theme.colors.layout.darkest}, | ||
${theme.colors.layout.dark}, | ||
${theme.colors.layout.dark}, | ||
${theme.colors.layout.darkest} | ||
); | ||
animation: ${animated ? "skeleton 8s ease-in-out infinite" : "none"}; | ||
`} | ||
${({ boxHeight, height }) => | ||
boxHeight && | ||
Number.isFinite(height) && | ||
boxHeight - ((height as number) || 24) > 0 && | ||
`margin-bottom: ${boxHeight - ((height as number) || 24)}px`}; | ||
@keyframes skeleton { | ||
0% { | ||
background-position: 200% 0; | ||
} | ||
to { | ||
background-position: -200% 0; | ||
} | ||
} | ||
`; | ||
|
||
export default Skeleton; |
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,8 @@ | ||
/** | ||
* isString is a utility function that checks if a value is a string. | ||
*/ | ||
const isString = (x: any) => { | ||
return Object.prototype.toString.call(x) === "[object String]"; | ||
}; | ||
|
||
export default isString; |
0fe26c8
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:
kitchen-docs – ./docs
kitchen-docs-git-antoinekm-docs-onruntime.vercel.app
kitchen-docs.vercel.app
kitchen.tonightpass.com
kitchen-docs-onruntime.vercel.app
design.tonightpass.com