Skip to content

Commit

Permalink
Feat(web-react): Introduce ActionLayout component #DS-1309
Browse files Browse the repository at this point in the history
  • Loading branch information
curdaj committed Jun 24, 2024
1 parent a8284ae commit 02ae749
Show file tree
Hide file tree
Showing 12 changed files with 153 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/web-react/scripts/entryPoints.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ const entryPoints = [
{ dirs: ['components', 'TextFieldBase'] },
{ dirs: ['components', 'Toast'] },
{ dirs: ['components', 'Tooltip'] },
{ dirs: ['components', 'UNSTABLE_ActionLayout'] },
{ dirs: ['components', 'UNSTABLE_Avatar'] },
{ dirs: ['components', 'UNSTABLE_Divider'] },
{ dirs: ['components', 'UNSTABLE_Slider'] },
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# UNSTABLE ActionLayout

⚠️ This component is UNSTABLE. It may significantly change at any point in the future.
Please use it with caution.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import classNames from 'classnames';
import React, { ReactElement } from 'react';
import { useStyleProps } from '../../hooks';
import { SpiritActionLayoutProps } from '../../types/actionLayout';
import { useActionLayoutStyleProps } from './useActionLayoutStyleProps';

export const UNSTABLE_ActionLayout = (props: SpiritActionLayoutProps): ReactElement => {
const { children, ...restProps } = props;
const { classProps, props: modifiedProps } = useActionLayoutStyleProps(restProps);
const { styleProps, props: otherProps } = useStyleProps(modifiedProps);

return (
<div {...otherProps} className={classNames(classProps.root, styleProps.className)} style={styleProps.style}>
{children}
</div>
);
};

export default UNSTABLE_ActionLayout;
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
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_ActionLayout from '../UNSTABLE_ActionLayout';

describe('UNSTABLE_ActionLayout', () => {
classNamePrefixProviderTest(UNSTABLE_ActionLayout, 'UNSTABLE_ActionLayout');

stylePropsTest(UNSTABLE_ActionLayout);

restPropsTest(UNSTABLE_ActionLayout, 'div');

beforeEach(() => {
render(<UNSTABLE_ActionLayout>Content</UNSTABLE_ActionLayout>);
});

it('should render content', () => {
expect(screen.getByText('Content')).toBeInTheDocument();
});

it('should render children', () => {
expect(screen.getByText('Content')).toHaveClass('UNSTABLE_ActionLayout');
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { renderHook } from '@testing-library/react';
import { useActionLayoutStyleProps } from '../useActionLayoutStyleProps';

describe('useActionLayoutStyleProps', () => {
it('should return defaults', () => {
const props = {};
const { result } = renderHook(() => useActionLayoutStyleProps(props));

expect(result.current.classProps.root).toBe('UNSTABLE_ActionLayout');
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import React from 'react';
import { ButtonLink } from '../../Button';
import { UNSTABLE_ActionLayout } from '../index';

const ActionLayoutDefault = () => (
<UNSTABLE_ActionLayout>
<ButtonLink color="primary" href="#">
Primary Action
</ButtonLink>
<ButtonLink color="secondary" href="#">
Secondary Action
</ButtonLink>
</UNSTABLE_ActionLayout>
);

export default ActionLayoutDefault;
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 ActionLayoutDefault from './ActionLayoutDefault';

ReactDOM.createRoot(document.getElementById('root') as HTMLElement).render(
<React.StrictMode>
<DocsSection title="Default" stackAlignment="stretch">
<ActionLayoutDefault />
</DocsSection>
</React.StrictMode>,
);
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{> web-react/demo}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export { default as UNSTABLE_ActionLayout } from './UNSTABLE_ActionLayout';
export * from './UNSTABLE_ActionLayout';
export * from './useActionLayoutStyleProps';
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { Markdown } from '@storybook/blocks';
import type { Meta, StoryObj } from '@storybook/react';
import React from 'react';
import { ButtonLink } from '../../Button';
import ReadMe from '../README.md';
import { UNSTABLE_ActionLayout } from '..';

const meta: Meta<typeof UNSTABLE_ActionLayout> = {
title: 'Experimental/UNSTABLE_ActionLayout',
component: UNSTABLE_ActionLayout,
parameters: {
docs: {
page: () => <Markdown>{ReadMe}</Markdown>,
},
},
argTypes: {},
args: {
children: (
<>
<ButtonLink color="primary" href="/">
Primary Action
</ButtonLink>
<ButtonLink color="secondary" href="/">
Secondary Action
</ButtonLink>
</>
),
},
};

export default meta;
type Story = StoryObj<typeof UNSTABLE_ActionLayout>;

export const Playground: Story = {
name: 'UNSTABLE_ActionLayout',
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { useClassNamePrefix } from '../../hooks';
import { SpiritActionLayoutProps } from '../../types/actionLayout';

export interface ActionLayoutStyles<T> {
classProps: {
root: string;
};
props: T;
}

export function useActionLayoutStyleProps(props: SpiritActionLayoutProps): ActionLayoutStyles<SpiritActionLayoutProps> {
const actionLayoutClass = useClassNamePrefix('UNSTABLE_ActionLayout');

return {
classProps: {
root: actionLayoutClass,
},
props,
};
}
3 changes: 3 additions & 0 deletions packages/web-react/src/types/actionLayout.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { ChildrenProps, StyleProps } from './shared';

export interface SpiritActionLayoutProps extends ChildrenProps, StyleProps {}

0 comments on commit 02ae749

Please sign in to comment.