-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
merge branch 'main' into improve-filter
- Loading branch information
Showing
8 changed files
with
136 additions
and
32 deletions.
There are no files selected for viewing
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
52 changes: 52 additions & 0 deletions
52
src/components/content/WithPlaceholder/WithPlacehoder.stories.tsx
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,52 @@ | ||
import { | ||
Controls, | ||
Description, | ||
Primary, | ||
Stories, | ||
Subheading, | ||
Title, | ||
} from '@storybook/blocks' | ||
import { Meta, StoryObj } from '@storybook/react' | ||
import { WithPlaceholder } from './WithPlaceholder' | ||
|
||
const children = { | ||
options: ['Null', 'Undefined', 'Empty text', 'ReactNode'], | ||
mapping: { | ||
Null: null, | ||
Undefined: undefined, | ||
'Empty text': '', | ||
ReactNode: 'John Doe', | ||
}, | ||
control: { type: 'select' }, | ||
} | ||
|
||
const meta = { | ||
title: 'Components/Content/WithPlaceHolder', | ||
component: WithPlaceholder, | ||
args: { | ||
placeholder: '-', | ||
children: 'John Doe', | ||
}, | ||
argTypes: { | ||
children, | ||
}, | ||
parameters: { | ||
docs: { | ||
page: () => ( | ||
<> | ||
<Title /> | ||
<Description /> | ||
<Primary /> | ||
<Subheading>Props</Subheading> | ||
<Controls /> | ||
<Stories /> | ||
</> | ||
), | ||
}, | ||
}, | ||
} satisfies Meta<typeof WithPlaceholder> | ||
export default meta | ||
|
||
type Story = StoryObj<typeof meta> | ||
|
||
export const Default: Story = {} |
26 changes: 26 additions & 0 deletions
26
src/components/content/WithPlaceholder/WithPlaceholder.tsx
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,26 @@ | ||
import { PropsWithChildren, ReactNode } from 'react' | ||
|
||
export type WithPlaceholderProps = PropsWithChildren<{ | ||
/** | ||
* Defines the placeholder to be rendered if the children is not valid. | ||
*/ | ||
placeholder?: ReactNode | ||
}> | ||
|
||
/** | ||
* This component validates the content and displays a placeholder if the content is empty, null or undefined. | ||
*/ | ||
export function WithPlaceholder({ | ||
placeholder = '-', | ||
children, | ||
}: WithPlaceholderProps) { | ||
return ( | ||
<> | ||
{typeof children === 'number' | ||
? isNaN(children) | ||
? placeholder | ||
: children | ||
: children || placeholder} | ||
</> | ||
) | ||
} |
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
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