Skip to content

Commit

Permalink
Merge pull request #35 from sha-el/feature/v0.2.0
Browse files Browse the repository at this point in the history
V0.2.0 release fixes
  • Loading branch information
anitnilay20 authored Dec 8, 2020
2 parents 0b9c0f1 + 3c4b01a commit 37f3ddd
Show file tree
Hide file tree
Showing 54 changed files with 1,281 additions and 784 deletions.
1 change: 1 addition & 0 deletions src/components/AutoComplete/AutoComplete.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export const Single: Story<SingleAutoComplete<string>> = () => {
value={value}
displayValue={(e) => e as string}
onChange={(e: string) => update(e)}
hint="Select an alter ego"
/>
);
};
Expand Down
72 changes: 55 additions & 17 deletions src/components/AutoComplete/AutoComplete.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import { lightText } from '../../helpers/color';
import { Skeleton } from '../Loading';

export class AutoComplete<T> extends React.Component<AutoCompleteProps<T>, State<T>> {
dataActualLength = 0;

constructor(props) {
super(props);

Expand All @@ -20,6 +22,7 @@ export class AutoComplete<T> extends React.Component<AutoCompleteProps<T>, State
data: [],
open: false,
loading: false,
selected: -1,
};
}

Expand All @@ -41,33 +44,43 @@ export class AutoComplete<T> extends React.Component<AutoCompleteProps<T>, State
items = await items;
this.setState({ loading: false });
}
this.dataActualLength = items.length;
this.setState({ data: items });
};

onOpen = (open: boolean) => {
if (this.props.disabled) {
return;
}
if (!open) {
return this.setState({ open, selected: -1, search: '' });
}
open && this.fetchData();
this.setState({ open });
};

displayList = () => {
const { data, search, loading } = this.state;
const { data, search, loading, selected } = this.state;
const { listDisplayProp, uniqueIdentifier, searchValue } = this.props;

const filteredData = data?.filter((v) => searchValue(v).toLowerCase().includes(search.toLowerCase()));

this.dataActualLength = filteredData.length;

return (
<Skeleton
isLoading={loading}
render={() => (
<List style={{ maxHeight: '300px', overflowY: 'auto' }}>
{data
.filter((v) => searchValue(v).toLowerCase().includes(search))
.map((v) => (
<ListItem key={uniqueIdentifier(v)} selected={this.isItemSelected(v)} onClick={() => this.onChange(v)}>
{listDisplayProp(v)}
</ListItem>
))}
<List densed style={{ maxHeight: '300px', overflowY: 'auto' }}>
{filteredData?.map((v, i) => (
<ListItem
key={uniqueIdentifier(v)}
selected={this.isItemSelected(v) || selected === i}
onClick={() => this.onChange(v)}
>
{listDisplayProp(v)}
</ListItem>
))}
</List>
)}
/>
Expand Down Expand Up @@ -166,7 +179,7 @@ export class AutoComplete<T> extends React.Component<AutoCompleteProps<T>, State
this.setState({ search }, this.fetchData);
};

onChange = (selected: AutoCompleteProps<T>['value']) => {
onChange = (selected: T) => {
const { mode, value, onChange, uniqueIdentifier } = this.props;
if (mode === 'single') {
onChange(selected as never);
Expand All @@ -185,13 +198,37 @@ export class AutoComplete<T> extends React.Component<AutoCompleteProps<T>, State
this.setState({ search: '' });
};

onKeyUp = (e: React.KeyboardEvent) => {
switch (e.which) {
case 27: {
return this.onOpen(false);
onKeyDown = (e: React.KeyboardEvent) => {
const { data, selected, open } = this.state;
switch (e.key) {
case 'ArrowDown': {
if (!open) {
return this.onOpen(true);
}

if (selected === this.dataActualLength - 1) {
return this.setState({ selected: -1 });
}

return this.setState({ selected: selected + 1 });
}
case 9: {
return this.onOpen(true);
case 'ArrowUp': {
if (!open) {
return this.onOpen(true);
}

if (selected === -1) {
return this.setState({ selected: this.dataActualLength - 1 });
}

return this.setState({ selected: selected - 1 });
}
case 'Enter': {
if (selected === -1) {
return;
}

return this.onChange(data[selected]);
}
}
};
Expand All @@ -209,7 +246,7 @@ export class AutoComplete<T> extends React.Component<AutoCompleteProps<T>, State
value: this.displayValue(),
before: this.renderBefore(),
onChange: (e) => this.onSearch(e.target.value),
onKeyUp: this.onKeyUp,
onKeyDown: this.onKeyDown,
required,
disabled: this.props.disabled,
});
Expand Down Expand Up @@ -269,4 +306,5 @@ interface State<T> {
data: T[];
open: boolean;
loading: boolean;
selected: number;
}
13 changes: 7 additions & 6 deletions src/components/Breadcrumb/Breadcrumb.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { Story, Meta } from '@storybook/react';

import { MdHome, MdNavigateNext } from 'react-icons/md';
import { Breadcrumb, BreadcrumbProps } from './Breadcrumb';
import { MenuItemGroup, MenuItem } from '../Menu';
import { MenuItem, Menu } from '../Menu';
import { Button } from '../Button';

export default {
title: 'Navigation/Breadcrumb',
Expand All @@ -27,8 +28,8 @@ Icons.args = {
paths: [() => <a href="#">Home</a>, () => <a href="#">Breadcrumb</a>],
};

export const Menu = Template.bind({});
Menu.args = {
export const WithMenu = Template.bind({});
WithMenu.args = {
seperator: '>',
paths: [
() => (
Expand All @@ -37,9 +38,9 @@ Menu.args = {
</a>
),
() => (
<MenuItemGroup title="hello" inline={false}>
<MenuItem name="1">Option 1</MenuItem>
</MenuItemGroup>
<Menu anchor={<Button flat>Options</Button>}>
<MenuItem>Option 1</MenuItem>
</Menu>
),
],
};
37 changes: 21 additions & 16 deletions src/components/Button/Button.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ export default {
const BlockTemplate: Story<AnchorButtonProps & NativeButtonProps> = (args) => (
<>
<Button {...args}>Default</Button>
<Button {...args} type="primary">
<Button {...args} primary>
Primary
</Button>
<Button {...args} type="secondary">
<Button {...args} secondary>
Secondary
</Button>
<Button {...args} type="danger">
<Button {...args} danger>
Danger
</Button>
<Button {...args} type="link">
<Button {...args} link>
Link
</Button>
</>
Expand All @@ -35,16 +35,16 @@ const BlockTemplate: Story<AnchorButtonProps & NativeButtonProps> = (args) => (
const MixedTemplate: Story<AnchorButtonProps & NativeButtonProps> = (args) => (
<>
<Button {...args}>Default</Button>
<Button {...args} type="primary">
<Button {...args} primary>
Primary
</Button>
<Button {...args} outline type="secondary">
<Button {...args} outline secondary>
Secondary
</Button>
<Button {...args} flat type="danger">
<Button {...args} flat danger>
Danger
</Button>
<Button {...args} type="link">
<Button {...args} link>
Link
</Button>
</>
Expand All @@ -53,11 +53,11 @@ const MixedTemplate: Story<AnchorButtonProps & NativeButtonProps> = (args) => (
const CircleTemplate: Story<AnchorButtonProps & NativeButtonProps> = (args) => (
<>
<Button {...args} shape="circle" />
<Button {...args} type="primary" shape="circle" />
<Button {...args} type="secondary" outline shape="circle" />
<Button {...args} type="secondary" flat shape="circle" />
<Button {...args} type="danger" disabled shape="circle" />
<Button {...args} type="link" shape="circle" />
<Button {...args} primary shape="circle" />
<Button {...args} secondary outline shape="circle" />
<Button {...args} secondary flat shape="circle" />
<Button {...args} danger disabled shape="circle" />
<Button {...args} link shape="circle" />
</>
);

Expand Down Expand Up @@ -98,11 +98,16 @@ Loading.args = {
loading: true,
};

export const Size = MixedTemplate.bind({});
Size.args = {
size: 'big',
};

export const Group = () => (
<ButtonGroup>
<Button>Default</Button>
<Button type="primary">Primary</Button>
<Button type="secondary">Secondary</Button>
<Button type="danger">Danger</Button>
<Button primary>Primary</Button>
<Button secondary>Secondary</Button>
<Button danger>Danger</Button>
</ButtonGroup>
);
Loading

0 comments on commit 37f3ddd

Please sign in to comment.