-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat(web-react): Introduce UNSTABLE_Divider component #DS-1303
Please use it with caution.
- Loading branch information
Showing
15 changed files
with
136 additions
and
0 deletions.
There are no files selected for viewing
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
20 changes: 20 additions & 0 deletions
20
packages/web-react/src/components/UNSTABLE_Divider/README.md
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,20 @@ | ||
# UNSTABLE Divider | ||
|
||
⚠️ This component is UNSTABLE. It may significantly change at any point in the future. | ||
Please use it with caution. | ||
|
||
The `UNSTABLE_Divider` component is used to separate content in a layout. | ||
|
||
```jsx | ||
<UNSTABLE_Divider /> | ||
``` | ||
|
||
## API | ||
|
||
The components accept [additional attributes][readme-additional-attributes]. | ||
If you need more control over the styling of a component, you can use [style props][readme-style-props] | ||
and [escape hatches][readme-escape-hatches]. | ||
|
||
[readme-additional-attributes]: https://github.com/lmc-eu/spirit-design-system/blob/main/packages/web-react/README.md#additional-attributes | ||
[readme-escape-hatches]: https://github.com/lmc-eu/spirit-design-system/blob/main/packages/web-react/README.md#escape-hatches | ||
[readme-style-props]: https://github.com/lmc-eu/spirit-design-system/blob/main/packages/web-react/README.md#style-props |
14 changes: 14 additions & 0 deletions
14
packages/web-react/src/components/UNSTABLE_Divider/UNSTABLE_Divider.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,14 @@ | ||
import classNames from 'classnames'; | ||
import React from 'react'; | ||
import { useStyleProps } from '../../hooks'; | ||
import { SpiritDividerProps } from '../../types'; | ||
import { useDividerStyleProps } from './useDividerStyleProps'; | ||
|
||
export const UNSTABLE_Divider = (props: SpiritDividerProps): JSX.Element => { | ||
const { classProps, props: modifiedProps } = useDividerStyleProps(props); | ||
const { styleProps, props: otherProps } = useStyleProps(modifiedProps); | ||
|
||
return <hr {...otherProps} {...styleProps} className={classNames(classProps, styleProps.className)} />; | ||
}; | ||
|
||
export default UNSTABLE_Divider; |
21 changes: 21 additions & 0 deletions
21
packages/web-react/src/components/UNSTABLE_Divider/__tests__/UNSTABLE_Divider.test.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,21 @@ | ||
import '@testing-library/jest-dom'; | ||
import { render, screen } from '@testing-library/react'; | ||
import React from 'react'; | ||
import { classNamePrefixProviderTest } from '../../../../tests/providerTests/classNamePrefixProviderTest'; | ||
import { restPropsTest } from '../../../../tests/providerTests/restPropsTest'; | ||
import { stylePropsTest } from '../../../../tests/providerTests/stylePropsTest'; | ||
import UNSTABLE_Divider from '../UNSTABLE_Divider'; | ||
|
||
describe('UNSTABLE_Divider', () => { | ||
classNamePrefixProviderTest(UNSTABLE_Divider, 'UNSTABLE_Divider'); | ||
|
||
stylePropsTest(UNSTABLE_Divider); | ||
|
||
restPropsTest(UNSTABLE_Divider, 'hr'); | ||
|
||
it('should have default classname', () => { | ||
render(<UNSTABLE_Divider />); | ||
|
||
expect(screen.getByRole('separator')).toHaveClass('UNSTABLE_Divider'); | ||
}); | ||
}); |
11 changes: 11 additions & 0 deletions
11
packages/web-react/src/components/UNSTABLE_Divider/__tests__/useDividerStyleProps.test.ts
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,11 @@ | ||
import { renderHook } from '@testing-library/react-hooks'; | ||
import { useDividerStyleProps } from '../useDividerStyleProps'; | ||
|
||
describe('useDividerStyleProps', () => { | ||
it('should return defaults', () => { | ||
const props = {}; | ||
const { result } = renderHook(() => useDividerStyleProps(props)); | ||
|
||
expect(result.current.classProps).toBe('UNSTABLE_Divider'); | ||
}); | ||
}); |
6 changes: 6 additions & 0 deletions
6
packages/web-react/src/components/UNSTABLE_Divider/demo/DividerDefault.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,6 @@ | ||
import React from 'react'; | ||
import UNSTABLE_Divider from '../UNSTABLE_Divider'; | ||
|
||
const DividerDefault = () => <UNSTABLE_Divider />; | ||
|
||
export default DividerDefault; |
12 changes: 12 additions & 0 deletions
12
packages/web-react/src/components/UNSTABLE_Divider/demo/index.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,12 @@ | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom/client'; | ||
import DocsSection from '../../../../docs/DocsSections'; | ||
import DividerDefault from './DividerDefault'; | ||
|
||
ReactDOM.createRoot(document.getElementById('root') as HTMLElement).render( | ||
<React.StrictMode> | ||
<DocsSection title="Default" stackAlignment="stretch"> | ||
<DividerDefault /> | ||
</DocsSection> | ||
</React.StrictMode>, | ||
); |
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 @@ | ||
{{> web-react/demo}} |
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,3 @@ | ||
export * from './UNSTABLE_Divider'; | ||
export * from './useDividerStyleProps'; | ||
export { default as UNSTABLE_Divider } from './UNSTABLE_Divider'; |
24 changes: 24 additions & 0 deletions
24
packages/web-react/src/components/UNSTABLE_Divider/stories/UNSTABLE_Divider.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,24 @@ | ||
import { Markdown } from '@storybook/blocks'; | ||
import type { Meta, StoryObj } from '@storybook/react'; | ||
import React from 'react'; | ||
import ReadMe from '../README.md'; | ||
import { UNSTABLE_Divider } from '..'; | ||
|
||
const meta: Meta<typeof UNSTABLE_Divider> = { | ||
title: 'Components/UNSTABLE_Divider', | ||
component: UNSTABLE_Divider, | ||
parameters: { | ||
docs: { | ||
page: () => <Markdown>{ReadMe}</Markdown>, | ||
}, | ||
}, | ||
argTypes: {}, | ||
args: {}, | ||
}; | ||
|
||
export default meta; | ||
type Story = StoryObj<typeof UNSTABLE_Divider>; | ||
|
||
export const Playground: Story = { | ||
name: 'UNSTABLE_Divider', | ||
}; |
18 changes: 18 additions & 0 deletions
18
packages/web-react/src/components/UNSTABLE_Divider/useDividerStyleProps.ts
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,18 @@ | ||
import { useClassNamePrefix } from '../../hooks'; | ||
import { SpiritDividerProps } from '../../types'; | ||
|
||
export interface DividerStyles { | ||
/** className props */ | ||
classProps: string; | ||
/** props to be passed to the element */ | ||
props: SpiritDividerProps; | ||
} | ||
|
||
export function useDividerStyleProps(props: SpiritDividerProps): DividerStyles { | ||
const DividerClass = useClassNamePrefix('UNSTABLE_Divider'); | ||
|
||
return { | ||
classProps: DividerClass, | ||
props, | ||
}; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { StyleProps, TransferProps } from './shared'; | ||
|
||
export interface SpiritDividerProps extends StyleProps, TransferProps {} |
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
Binary file modified
BIN
-6.12 KB
(93%)
tests/e2e/demo-homepages.spec.ts-snapshots/web-react-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.