Skip to content

Commit 410387e

Browse files
authored
fix: Options Styles (#260)
1 parent 8539ccf commit 410387e

12 files changed

+28
-29
lines changed
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading

packages/fuselage/src/components/AutoComplete/index.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import React, { useState, useEffect, useRef } from 'react';
33
import { Box, PositionAnimated } from '../Box';
44
import { Chip } from '../Chip';
55
import { Icon } from '../Icon';
6-
import { useCursor, Options, OptionAvatar } from '../Options';
6+
import { useCursor, Options } from '../Options';
77
import { InputBox } from '../InputBox';
88

99
const Item = (props) => <Box is='div' marginInline='x4' {...props} />;
@@ -53,7 +53,7 @@ export function AutoComplete({
5353
onChange(currentValue);
5454
}, [currentValue, onChange]);
5555

56-
const [cursor, handleKeyDown, setCursor, reset, [visible, hide, show]] = useCursor(value, options, onChange);
56+
const [cursor, handleKeyDown, , reset, [visible, hide, show]] = useCursor(value, options, onChange);
5757

5858
useEffect(reset, [filter]);
5959

@@ -65,7 +65,7 @@ export function AutoComplete({
6565
</Chip.Wrapper>
6666
<Addon children={<Icon name='magnifier' size='x20' />}/>
6767
<PositionAnimated visible={visible} anchor={containerRef}>
68-
<Options role='option' renderEmpty={renderEmpty} renderItem={OptionAvatar} setCursor={setCursor} cursor={cursor} value={value} options={options.map(({ label, value }) => [value, label])} />
68+
<Options role='option' renderEmpty={renderEmpty} cursor={cursor} value={value} options={options.map(({ label, value }) => [value, label])} />
6969
</PositionAnimated>
7070
</Container>
7171
);

packages/fuselage/src/components/Options/index.js

+12-22
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import React, { useCallback, useLayoutEffect, useState, forwardRef, useMemo } from 'react';
22

33

4-
import { AnimatedVisibility, Box, Flex, Margins, Scrollable } from '../Box';
4+
import { AnimatedVisibility, Box, Margins, Scrollable } from '../Box';
5+
import { Icon } from '../Icon';
56
import { Avatar } from '../Avatar';
67
import { CheckBox } from '../CheckBox';
78
import { Tile } from '../Tile';
@@ -21,24 +22,15 @@ const prevent = (e) => {
2122
e.stopPropagation();
2223
};
2324

24-
const Li = forwardRef(function Li(props, ref) {
25-
return <Box is='li' rcx-option ref={ref} {...props} />;
25+
const Li = forwardRef(function Li({ children, ...props }, ref) {
26+
return <Box rcx-option withTruncatedText display='flex' alignItems='center' is='li' ref={ref} {...props}><Margins inline='x4'>{children}</Margins></Box>;
2627
});
2728

28-
export const Empty = React.memo(() => <Box is='span' fontScale='p1' color='hint'>Empty</Box>);
29+
export const Option = React.memo(({ id, avatar, children, label = children, focus, selected, icon, ...options }) => <Li key={id} rcx-option--focus={focus} id={id} rcx-option--selected={selected} aria-selected={selected} {...options}>{avatar && <Avatar size='x28' url={avatar} tile={label}/>}{icon && <Icon size='x16' name={icon}/>} <Box is='span' withTruncatedText flexGrow={1} fontScale='p1' color='default'>{label}</Box>{label !== children && children}</Li>);
2930

30-
export const Option = React.memo(({ id, children: label, focus, selected, ...options }) => <Li key={id} rcx-option--focus={focus} id={id} rcx-option--selected={selected} aria-selected={selected} {...options}>{label}</Li>);
31+
export const Empty = React.memo(() => <Option is='span' fontScale='p1' color='hint'>Empty</Option>);
3132

32-
export const CheckOption = React.memo(({ id, children: label, focus, selected, ...options }) => <Li key={id} rcx-option--focus={focus} id={id} aria-selected={selected} {...options}><Margins inline='x4'><CheckBox checked={selected} /></Margins><Margins inline='x4'><Box is='span' fontScale='p1' color='default'>{label}</Box></Margins></Li>);
33-
34-
export const OptionAvatar = React.memo(({ id, value, children: label, focus, selected, ...options }) => (
35-
<Flex.Container>
36-
<Li key={id} rcx-option--focus={focus} id={id} rcx-option--selected={selected} aria-selected={selected} {...options}>
37-
<Margins inline='x4'><Avatar size='x20' url={value} tile={label}/></Margins>
38-
<Margins inline='x4'><Box is='span' fontScale='p1' color='default'>{label}</Box></Margins>
39-
</Li>
40-
</Flex.Container>
41-
));
33+
export const CheckOption = React.memo(({ selected, children: label, ...options }) => <Option label={label} selected={selected} {...options}><CheckBox checked={selected} /></Option>);
4234

4335
export const Options = React.forwardRef(({
4436
maxHeight = '144px',
@@ -63,14 +55,12 @@ export const Options = React.forwardRef(({
6355

6456
const optionsMemoized = useMemo(() => options.map(([value, label, selected], i) => <OptionComponent role='option' onMouseDown={(e) => prevent(e) & onSelect([value, label]) && false} key={value} value={value} selected={selected || (multiple !== true && null)} focus={cursor === i || null}>{label}</OptionComponent>), [options, multiple, cursor, onSelect]);
6557
return <Box rcx-options is='div' {...props}>
66-
<Tile padding='x8' elevation='2'>
58+
<Tile padding={0} paddingBlock={'x12'} paddingInline={0} elevation='2'>
6759
<Scrollable vertical smooth>
68-
<Margins blockStart='x4'>
69-
<Tile ref={ref} elevation='0' padding='none' maxHeight={maxHeight} onMouseDown={prevent} onClick={prevent} is='ol' aria-multiselectable={multiple} role='listbox' aria-multiselectable='true' aria-activedescendant={options && options[cursor] && options[cursor][0]}>
70-
{!options.length && <EmptyComponent/>}
71-
{optionsMemoized}
72-
</Tile>
73-
</Margins>
60+
<Tile ref={ref} elevation='0' padding='none' maxHeight={maxHeight} onMouseDown={prevent} onClick={prevent} is='ol' aria-multiselectable={multiple} role='listbox' aria-multiselectable='true' aria-activedescendant={options && options[cursor] && options[cursor][0]}>
61+
{!options.length && <EmptyComponent/>}
62+
{optionsMemoized}
63+
</Tile>
7464
</Scrollable>
7565
</Tile>
7666
</Box>;

packages/fuselage/src/components/Options/stories.mdx

+12-3
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ import { Meta, Preview, Props, Story } from '@storybook/addon-docs/blocks';
33
import LinkTo from '@storybook/addon-links/react';
44
import { PropsVariationSection } from '../../../.storybook/helpers';
55
import { Box } from '../'
6-
import { Options, CheckOption, OptionAvatar } from './';
6+
import { Options, CheckOption, Option } from './';
77
const thumb = 'data:image/gif;base64,R0lGODlhAQABAIAAAMLCwgAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==';
88
const options = [
99
[1, 'a teste 1'],
1010
[2, 'b teste 2'],
1111
[3, 'c teste 3', true],
12-
[4, 'd teste 4'],
12+
[4, 'd testeadsasdasdasdasdjhasjfhasdkjfhaskdfjhkasjdfhkasjdhfkasjdhfkasjdhfkasjdhfkasdjhfkasdjhfaksjdfhkasjdh 4'],
1313
];
1414

1515
<Meta title='Misc/Options' parameters={{ jest: ['Options/spec'] }} />
@@ -26,6 +26,15 @@ An input for selection of options.
2626
</Story>
2727
</Preview>
2828

29+
30+
<Preview>
31+
<Story name='Option'>
32+
<Box position='relative' maxWidth={250}>
33+
<Options ref={React.createRef()} options={options} renderItem={Option} cursor={1} />
34+
</Box>
35+
</Story>
36+
</Preview>
37+
2938
<Props of={Options} />
3039

3140
<Preview>
@@ -39,7 +48,7 @@ An input for selection of options.
3948
<Preview>
4049
<Story name='OptionAvatar'>
4150
<Box position='relative' maxWidth={250}>
42-
<Options ref={React.createRef()} renderItem={(props) => <OptionAvatar {...props} value={thumb}/>} options={options} />
51+
<Options ref={React.createRef()} renderItem={(props) => <Option {...props} avatar={thumb}/>} options={options} />
4352
</Box>
4453
</Story>
4554
</Preview>

packages/fuselage/src/components/Options/styles.scss

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
@include typography.use-font-scale(p2);
88
@include typography.use-text-ellipsis;
99

10-
padding: lengths.padding(8);
10+
padding: lengths.padding(4) lengths.padding(16);
1111

1212
list-style: none;
1313

0 commit comments

Comments
 (0)