Skip to content

Commit

Permalink
🔀 merge branch 'develop' into antoinekm/docs
Browse files Browse the repository at this point in the history
  • Loading branch information
AntoineKM committed Dec 6, 2022
2 parents dd3f7a7 + 2d32e7a commit 0fe26c8
Show file tree
Hide file tree
Showing 6 changed files with 296 additions and 8 deletions.
17 changes: 9 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
</p>

<p align="center">
<a aria-label="onRuntime Studio" href="https://onruntime.com" target="_blank">
<a aria-label="onRuntime Studio" href="https://onruntime.com">
<img src="https://img.shields.io/badge/MADE%20BY%20ONRUNTIME-fff.svg?style=for-the-badge&labelColor=000">
</a>
<a aria-label="NPM version" href="https://www.npmjs.com/package/@tonightpass/kitchen" target="_blank">
<a aria-label="NPM version" href="https://npmjs.com/package/@tonightpass/kitchen">
<img alt="" src="https://img.shields.io/npm/v/@tonightpass/kitchen.svg?style=for-the-badge&labelColor=000000">
</a>
<a aria-label="License" href="https:/tonightpass/kitchen/blob/master/LICENSE" target="_blank">
<a aria-label="License" href="https:/tonightpass/kitchen/blob/master/LICENSE">
<img alt="" src="https://img.shields.io/npm/l/next.svg?style=for-the-badge&labelColor=000000">
</a>
</p>
Expand All @@ -27,13 +27,13 @@
Social
</h2>

<a aria-label="Discord" href="https://www.discord.gg/VvvAkPqQ98" target="_blank">
<a aria-label="Discord" href="https://discord.gg/VvvAkPqQ98">
<img alt="" src="https://img.shields.io/discord/829290979092856833?label=Discord&style=for-the-badge&labelColor=000000&logo=discord&logoColor=white&logoWidth=20">
</a>
<a aria-label="LinkedIn" href="https://www.linkedin.com/company/tonightpass" target="_blank">
<a aria-label="LinkedIn" href="https://linkedin.com/company/tonightpass">
<img alt="" src="https://img.shields.io/badge/LinkedIn-0e76a8.svg?style=for-the-badge&labelColor=000000&logo=linkedin&logoColor=white&logoWidth=20">
</a>
<a aria-label="Instagram" href="https://www.instagram.com/tonightpass" target="_blank">
<a aria-label="Instagram" href="https://instagram.com/tonightpass">
<img alt="" src="https://img.shields.io/badge/Instagram-C13584.svg?style=for-the-badge&labelColor=000000&logo=instagram&logoColor=white&logoWidth=20">
</a>
</p>
Expand All @@ -44,13 +44,13 @@

It's an UI Kit that can be used on every [React](https://reactjs.org) and [React Native](https://reactnative.dev/) project as a complete UI library with optimized and customizable components.

See [Kitchen Documentation](http://docs.onruntime.com/kitchen) for all details.
See [Kitchen Documentation](https://kitchen.tonightpass.com/docs) for all details.

This library use [Styled Component](https://styled-components.com/) as components styling and theme provider.

## Getting Started

Visit <a aria-label="tonightpass nestjs-mailjet" href="https://docs.onruntime.com/kitchen" target="_blank">/kitchen</a> to get started with Kitchen and see the full documentation.
Visit <a aria-label="tonightpass docs" href="https://kitchen.tonightpass.com/docs">/kitchen</a> to get started with Kitchen and see the full documentation.

## Community

Expand All @@ -68,6 +68,7 @@ Please see our [contributing rules](https://docs.onruntime.com/contributing/intr

- Antoine Kingue ([@antoinekm](https:/antoinekm))
- Jérémy Baudrin ([@jerembdn](https:/jerembdn))
- Younès Bessa ([@younesbessa](https:/younesbessa))

## License

Expand Down
1 change: 1 addition & 0 deletions examples/next-typescript/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const IndexPage: NextPage = () => {
<Link href={"/text"}>Text</Link>
<Link href={"/icon"}>Icon</Link>
<Link href={"/note"}>Note</Link>
<Link href={"/skeleton"}>Skeleton</Link>
</div>
);
};
Expand Down
117 changes: 117 additions & 0 deletions examples/next-typescript/pages/skeleton.tsx
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;
159 changes: 159 additions & 0 deletions packages/kitchen/src/components/Skeleton/index.tsx
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;
2 changes: 2 additions & 0 deletions packages/kitchen/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import UnorderedList from "./components/UnorderedList";
import ListItem from "./components/ListItem";
import Icon from "./components/Icon";
import InlineCode from "./components/InlineCode";
import Skeleton from "./components/Skeleton";
import Spinner from "./components/Spinner";
import Text from "./components/Text";

Expand All @@ -27,6 +28,7 @@ export {
OrderedList,
ListItem,
UnorderedList,
Skeleton,
Spinner,
Text,
};
Expand Down
8 changes: 8 additions & 0 deletions packages/kitchen/src/utils/isString.ts
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;

1 comment on commit 0fe26c8

@vercel
Copy link

@vercel vercel bot commented on 0fe26c8 Dec 6, 2022

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.