Skip to content

Commit

Permalink
feat(react): add Skeleton component
Browse files Browse the repository at this point in the history
  • Loading branch information
brionmario committed Oct 3, 2023
1 parent 1aafef7 commit f419b03
Show file tree
Hide file tree
Showing 7 changed files with 163 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/react/.storybook/story-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ export type Stories =
| 'RadioGroup'
| 'Select'
| 'SignIn'
| 'Skeleton'
| 'Snackbar'
| 'Stepper'
| 'Tab'
Expand Down Expand Up @@ -343,6 +344,9 @@ const StoryConfig: StorybookConfig = {
SignIn: {
hierarchy: `${StorybookCategories.Patterns}/Sign In`,
},
Skeleton: {
hierarchy: `${StorybookCategories.Feedback}/Skeleton`,
},
Snackbar: {
hierarchy: `${StorybookCategories.Feedback}/Snackbar`,
},
Expand Down
48 changes: 48 additions & 0 deletions packages/react/src/components/Skeleton/Skeleton.stories.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import {ArgsTable, Source, Story, Canvas, Meta} from '@storybook/addon-docs';
import dedent from 'ts-dedent';
import StoryConfig from '../../../.storybook/story-config.ts';
import Skeleton from './Skeleton.tsx';

export const meta = {
component: Skeleton,
title: StoryConfig.Skeleton.hierarchy,
};

<Meta title={meta.title} component={meta.component} />

export const Template = args => <Skeleton {...args} />;

# Skeleton

- [Overview](#overview)
- [Props](#props)
- [Usage](#usage)

## Overview

Display a placeholder preview of your content before the data gets loaded to reduce load-time frustration.

<Canvas>
<Story name="Overview">
{Template.bind({})}
</Story>
</Canvas>

## Props

<ArgsTable story="Overview" />

## Usage

Import and use the `Skeleton` component in your components as follows.

<Source
language="jsx"
dark
format
code={dedent`
import Skeleton from '@oxygen-ui/react/Skeleton';\n
function Demo() {
return <Skeleton />;
}`}
/>
45 changes: 45 additions & 0 deletions packages/react/src/components/Skeleton/Skeleton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/**
* Copyright (c) 2023, WSO2 LLC. (https://www.wso2.com). All Rights Reserved.
*
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import MuiSkeleton, {SkeletonProps as MuiSkeletonProps} from '@mui/material/Skeleton';
import clsx from 'clsx';
import {ElementType, FC, ReactElement} from 'react';
import {WithWrapperProps} from '../../models';
import {composeComponentDisplayName} from '../../utils';

export type SkeletonProps<C extends ElementType = ElementType> = {
component?: C;
} & Omit<MuiSkeletonProps<C>, 'component'>;

const COMPONENT_NAME: string = 'Skeleton';

const Skeleton: FC<SkeletonProps> & WithWrapperProps = <C extends ElementType>(
props: SkeletonProps<C>,
): ReactElement => {
const {className, ...rest} = props;

const classes: string = clsx('oxygen-Skeleton', className);

return <MuiSkeleton className={classes} {...rest} />;
};

Skeleton.displayName = composeComponentDisplayName(COMPONENT_NAME);
Skeleton.muiName = COMPONENT_NAME;
Skeleton.defaultProps = {};

export default Skeleton;
32 changes: 32 additions & 0 deletions packages/react/src/components/Skeleton/__test__/Skeleton.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* Copyright (c) 2023, WSO2 LLC. (https://www.wso2.com). All Rights Reserved.
*
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import {render} from '@unit-testing';
import Skeleton from '../Skeleton';

describe('Skeleton', () => {
it('should render successfully', () => {
const {baseElement} = render(<Skeleton />);
expect(baseElement).toBeTruthy();
});

it('should match the snapshot', () => {
const {baseElement} = render(<Skeleton />);
expect(baseElement).toMatchSnapshot();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Skeleton should match the snapshot 1`] = `
<body>
<div>
<span
class="MuiSkeleton-root MuiSkeleton-text MuiSkeleton-pulse oxygen-Skeleton css-abjlxe-MuiSkeleton-root"
/>
</div>
</body>
`;
20 changes: 20 additions & 0 deletions packages/react/src/components/Skeleton/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* Copyright (c) 2023, WSO2 LLC. (https://www.wso2.com). All Rights Reserved.
*
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

export {default} from './Skeleton';
export type {SkeletonProps} from './Skeleton';
3 changes: 3 additions & 0 deletions packages/react/src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,9 @@ export * from './Select';
export {default as SignIn} from './SignIn';
export * from './SignIn';

export {default as Skeleton} from './Skeleton';
export * from './Skeleton';

export {default as Stepper} from './Stepper';
export * from './Stepper';

Expand Down

0 comments on commit f419b03

Please sign in to comment.