Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add interactive demo of Dropdown placements #1148

Merged
merged 3 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
import React, { ChangeEvent, Ref, useState } from 'react';
import { DropdownRenderProps, PlacementDictionaryType } from '../../../types';
import { Button } from '../../Button';
import { Grid, GridItem } from '../../Grid';
import { Radio } from '../../Radio';
import { Dropdown } from '..';

const DropdownPlacements = () => {
const [placement, setPlacement] = useState<PlacementDictionaryType>('bottom-left');

const handlePlacementChange = (e: ChangeEvent<HTMLInputElement>) => {
setPlacement(e.target.value as PlacementDictionaryType);
};

const dropdownTrigger = ({ trigger: { className, ref, ...restOf } }: DropdownRenderProps) => (
<Button UNSAFE_className={className} ref={ref as Ref<HTMLButtonElement>} {...restOf}>
<span style={{ whiteSpace: 'nowrap' }}>{placement}</span>
</Button>
);

return (
<form autoComplete="off">
<Grid
cols={3}
UNSAFE_className="mx-auto"
UNSAFE_style={{ alignItems: 'center', justifyItems: 'center', maxWidth: '40rem' }}
>
<GridItem columnStart={2} rowStart={1}>
<Radio
name="placement"
isChecked={placement === 'top-left'}
isLabelHidden
onChange={handlePlacementChange}
id="placement_top_left"
label="top-left"
value="top-left"
/>{' '}
<Radio
name="placement"
isChecked={placement === 'top'}
isLabelHidden
onChange={handlePlacementChange}
id="placement_top"
label="top"
value="top"
/>{' '}
<Radio
name="placement"
isChecked={placement === 'top-right'}
isLabelHidden
onChange={handlePlacementChange}
id="placement_top_right"
label="top-right"
value="top-right"
/>
</GridItem>
<GridItem columnStart={2} rowStart={3}>
<Radio
name="placement"
isChecked={placement === 'bottom-left'}
isLabelHidden
onChange={handlePlacementChange}
id="placement_bottom_left"
label="bottom-left"
value="bottom-left"
/>{' '}
<Radio
name="placement"
isChecked={placement === 'bottom'}
isLabelHidden
onChange={handlePlacementChange}
id="placement_bottom"
label="bottom"
value="bottom"
/>{' '}
<Radio
name="placement"
isChecked={placement === 'bottom-right'}
isLabelHidden
onChange={handlePlacementChange}
id="placement_bottom_right"
label="bottom-right"
value="bottom-right"
/>
</GridItem>
<GridItem
columnStart={1}
rowStart={2}
UNSAFE_style={{ display: 'flex', flexDirection: 'column', justifySelf: 'start' }}
>
<Radio
name="placement"
isChecked={placement === 'left-top'}
isLabelHidden
onChange={handlePlacementChange}
id="placement_left_top"
label="left-top"
value="left-top"
/>
<Radio
name="placement"
isChecked={placement === 'left'}
isLabelHidden
onChange={handlePlacementChange}
id="placement_left"
label="left"
value="left"
/>
<Radio
name="placement"
isChecked={placement === 'left-bottom'}
isLabelHidden
onChange={handlePlacementChange}
id="placement_left_bottom"
label="left-bottom"
value="left-bottom"
/>
</GridItem>
<GridItem
columnStart={3}
rowStart={2}
UNSAFE_style={{ display: 'flex', flexDirection: 'column', justifySelf: 'end' }}
>
<Radio
name="placement"
isChecked={placement === 'right-top'}
isLabelHidden
onChange={handlePlacementChange}
id="placement_right_top"
label="right-top"
value="right-top"
/>
<Radio
name="placement"
isChecked={placement === 'right'}
isLabelHidden
onChange={handlePlacementChange}
id="placement_right"
label="right"
value="right"
/>
<Radio
name="placement"
isChecked={placement === 'right-bottom'}
isLabelHidden
onChange={handlePlacementChange}
id="placement_right_bottom"
label="right-bottom"
value="right-bottom"
/>
</GridItem>
<GridItem columnStart={2} rowStart={2}>
<div style={{ margin: '8rem auto' }}>
<Dropdown
enableAutoClose={false}
placement={placement as PlacementDictionaryType}
renderTrigger={dropdownTrigger}
>
<a href="#" className="d-flex mb-400">
Action
</a>
<a href="#" className="d-flex mb-400">
Another action
</a>
<a href="#" className="d-flex">
Something else here
</a>
</Dropdown>
</div>
</GridItem>
</Grid>
</form>
);
};

export default DropdownPlacements;
10 changes: 3 additions & 7 deletions packages/web-react/src/components/Dropdown/demo/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import ReactDOM from 'react-dom/client';
import icons from '@lmc-eu/spirit-icons/dist/icons';
import DocsSection from '../../../../docs/DocsSections';
import { IconsProvider } from '../../../context';
import DropdownDefault from './DropdownDefault';
import DropdownTopRight from './DropdownTopRight';
import DropdownPlacements from './DropdownPlacements';
import DropdownDisabledAutoclose from './DropdownDisabledAutoclose';
import DropdownLongerContent from './DropdownLongerContent';
import DropdownFullwidthAll from './DropdownFullwidthAll';
Expand All @@ -18,11 +17,8 @@ import DropdownEnhancedShadow from './DropdownEnhancedShadow';
ReactDOM.createRoot(document.getElementById('root') as HTMLElement).render(
<React.StrictMode>
<IconsProvider value={icons}>
<DocsSection title="Basic usage with default align">
<DropdownDefault />
</DocsSection>
<DocsSection title="Usage with align to top right">
<DropdownTopRight />
<DocsSection title="Placements" stackAlignment="stretch">
<DropdownPlacements />
</DocsSection>
<DocsSection title="Usage with disabled auto close">
<DropdownDisabledAutoclose />
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import React from 'react';
import DropdownModern from '../../Dropdown/DropdownModern';
import DropdownTrigger from '../../Dropdown/DropdownTrigger';
import DropdownPopover from '../../Dropdown/DropdownPopover';
import { Button } from '../../Button';
import { dropdownContent } from './constants';
import DropdownContentFactory from './DropdownContentFactory';

const DropdownModernEnhancedShadow = () => {
const [isOpen, setIsOpen] = React.useState(false);
const onToggle = () => setIsOpen(!isOpen);

return (
<div className="spirit-feature-dropdown-enable-enhanced-shadow">
<DropdownModern id="DropdownModernEnhancedShadow" isOpen={isOpen} onToggle={onToggle} placement="top-left">
<DropdownTrigger elementType={Button}>Finibus quis imperdiet, semper imperdiet aliquam</DropdownTrigger>
<DropdownPopover>
<DropdownContentFactory content={dropdownContent} />
</DropdownPopover>
</DropdownModern>
</div>
);
};

export default DropdownModernEnhancedShadow;
Loading