Skip to content

Commit

Permalink
Merge pull request #166 from Dias999/feature/Storybook-FormFieldSkeleton
Browse files Browse the repository at this point in the history
feat: storybook - formFieldSkeleton
  • Loading branch information
MrMaz authored Aug 1, 2024
2 parents 1ecaf09 + 7ae7fa6 commit 766d634
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import '@testing-library/jest-dom';
import React from 'react';
import { render } from '@testing-library/react';
import FormFieldSkeleton from '../src/components/FormFieldSkeleton';
import { FormFieldSkeleton } from '../src/components/FormFieldSkeleton';
import { TextField } from '../src/components/TextField';

describe('FormFieldSkeleton Component', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
SelectOption,
allOption,
} from '../../components/SelectField/SelectField';
import FormFieldSkeleton from '../../components/FormFieldSkeleton';
import { FormFieldSkeleton } from '../../components/FormFieldSkeleton';
import useDataProvider, { useQuery } from '@concepta/react-data-provider';
import { SimpleFilter } from 'components/Table/types';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,35 @@
import React, { PropsWithChildren } from 'react';
import { Box, Skeleton, useTheme } from '@mui/material';

type FormFieldSkeletonProps = {
/**
* FormFieldSkeleton component props.
*/
export type FormFieldSkeletonProps = {
/** Indicates if the form field is loading */
isLoading?: boolean;
/** Hides the label when set to true */
hideLabel?: boolean;
};

const FormFieldSkeleton = ({
/**
* The FormFieldSkeleton component is used to display a loading skeleton
* for form fields. It shows a skeleton text area and a skeleton input
* area when the form field is loading. The component supports options
* to hide the label and to toggle loading state.
*
* @see [Storybook - FormFieldSkeleton](https://storybook.rockets.tools/?path=/docs/formfieldskeleton)
*
* @example
* ```tsx
* <FormFieldSkeleton isLoading={true} hideLabel={true}>
* <YourComponent />
* </FormFieldSkeleton>
* ```
*
* @param props - FormFieldSkeleton component props
* @returns The skeleton loading component or the children if not loading
*/
export const FormFieldSkeleton = ({
isLoading = true,
children,
hideLabel,
Expand Down Expand Up @@ -38,5 +61,3 @@ const FormFieldSkeleton = ({
</Box>
);
};

export default FormFieldSkeleton;
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
SelectProps,
} from '@mui/material';

import FormFieldSkeleton from '../../components/FormFieldSkeleton';
import { FormFieldSkeleton } from '../../components/FormFieldSkeleton';

export const allOption: SelectOption = {
value: 'all',
Expand Down
6 changes: 4 additions & 2 deletions packages/react-material-ui/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,10 @@ export {
} from './components/Filter';
export { SchemaForm, SchemaFormProps } from './components/SchemaForm';

import FormFieldSkeleton from './components/FormFieldSkeleton';
export { FormFieldSkeleton };
export {
FormFieldSkeleton,
FormFieldSkeletonProps,
} from './components/FormFieldSkeleton';

export { default as ComposedTable } from './components/ComposedTable';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
} from '@rjsf/utils';
import { Autocomplete, createFilterOptions } from '@mui/material';
import useDataProvider, { useQuery } from '@concepta/react-data-provider';
import FormFieldSkeleton from '../../components/FormFieldSkeleton';
import { FormFieldSkeleton } from '../../components/FormFieldSkeleton';
import { allOption } from '../../components/SelectField/SelectField';
import { TextField } from '../../components/TextField';

Expand Down
41 changes: 41 additions & 0 deletions stories/FormFieldSkeleton.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import React from 'react';
import type { Meta, StoryObj } from '@storybook/react';
import { FormFieldSkeleton, TextField } from '@concepta/react-material-ui';

const meta = {
component: FormFieldSkeleton,
tags: ['autodocs'],
args: {
isLoading: true,
hideLabel: false,
},
argTypes: {
isLoading: { control: 'boolean' },
hideLabel: { control: 'boolean' },
},
render: (args) => (
<FormFieldSkeleton {...args}>
<TextField label="Text field" />
</FormFieldSkeleton>
),
} satisfies Meta<typeof FormFieldSkeleton>;

export default meta;

type Story = StoryObj<typeof meta>;

export const Default: Story = {
args: {},
};

export const WithoutLabel: Story = {
args: {
hideLabel: true,
},
};

export const NotLoading: Story = {
args: {
isLoading: false,
},
};

0 comments on commit 766d634

Please sign in to comment.