-
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.
* make select item form field fix height * lint fix * write store in tsx * lint fix * add default option to placeholder * fix lint error * fix typo in props description * Update src/components/content/WithPlaceholder/WithPlaceholder.tsx Co-authored-by: Alex Lanz <[email protected]> * Update src/components/content/WithPlaceholder/WithPlaceholder.tsx Co-authored-by: Alex Lanz <[email protected]> * Update src/components/content/WithPlaceholder/WithPlacehoder.stories.tsx Co-authored-by: Alex Lanz <[email protected]> * remove options from placeholder and cleanup * lint fix * lint fix * change props order --------- Co-authored-by: Alex Lanz <[email protected]>
- Loading branch information
Showing
3 changed files
with
79 additions
and
0 deletions.
There are no files selected for viewing
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