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

Object Switcher: Added props for combobox #1638

Closed
wants to merge 3 commits into from
Closed
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
4 changes: 4 additions & 0 deletions components/combobox/__docs__/site-stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ const siteStories = [
require('raw-loader!@salesforce/design-system-react/components/combobox/__examples__/readonly-single.jsx'),
require('raw-loader!@salesforce/design-system-react/components/combobox/__examples__/readonly-multiple.jsx'),
require('raw-loader!@salesforce/design-system-react/components/combobox/__examples__/required-input-error-state.jsx'),
require('raw-loader!@salesforce/design-system-react/components/combobox/__examples__/disabled.jsx'),
require('raw-loader!@salesforce/design-system-react/components/combobox/__examples__/inline-single-entity-combobox.jsx'),
require('raw-loader!@salesforce/design-system-react/components/combobox/__examples__/inline-single-search-add-entities.jsx'),
require('raw-loader!@salesforce/design-system-react/components/combobox/__examples__/inline-multiple-loading.jsx'),
];

module.exports = siteStories;
28 changes: 28 additions & 0 deletions components/combobox/__docs__/storybook-stories.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@ import { action } from '@storybook/addon-actions';
import { COMBOBOX } from '../../../utilities/constants';

import Base from '../__examples__/base';
import Disabled from '../__examples__/disabled';
import BaseMenuSubHeader from '../__examples__/base-menu-subheader';
import BaseMenuSeparator from '../__examples__/base-menu-separator';
import BaseInheritMenuWidth from '../__examples__/base-inherit-menu-width.jsx';
import RequiredInputErrorState from '../__examples__/required-input-error-state';
import PredefinedOptionsOnly from '../__examples__/base-predefined-options-only';
import InlineSingle from '../__examples__/inline-single';
import InlineSingleEntityCombobox from '../__examples__/inline-single-entity-combobox';
import InlineSingleSearchAddEntities from '../__examples__/inline-single-search-add-entities';
import InlineMultiple from '../__examples__/inline-multiple';
import InlineMultipleLoading from '../__examples__/inline-multiple-loading';
import BaseCustomMenuItem from '../__examples__/base-custom-menu-item';
import ReadOnly from '../__examples__/readonly-single';
import ReadOnlySingleSelectionCustomMenuItem from '../__examples__/readonly-single-selection-custom-menu-item';
Expand All @@ -33,17 +37,31 @@ import SnapshotReadonlyMultipleSelectionSingleItemSelected from '../__examples__
import SnapshotReadonlyMultipleSelectionMultipleItemsSelected from '../__examples__/snapshot/readonly-multiple-selection-multiple-items-selected';
import SnapshotReadonlySingleSelectionCustomMenuItemOpen from '../__examples__/snapshot/readonly-single-selection-custom-menu-item';
import SnapshotBaseLabelRequired from '../__examples__/snapshot/base-label-required';
import SnapshotInlineMultipleOpenLoading from '../__examples__/snapshot/inline-multiple-open-loading';
import SnapshotBaseDisabled from '../__examples__/snapshot/disabled';
import SnapshotInlineSingleSearchAddEntitiesOpen from '../__examples__/snapshot/inline-single-search-add-entities-open';
import SnapshotInlineSingleEntityCombobox from '../__examples__/snapshot/inline-single-entity-combobox';

storiesOf(COMBOBOX, module)
.addDecorator((getStory) => (
<div className="slds-p-around_medium">{getStory()}</div>
))
.add('Base', () => <Base action={action} />)
.add('Disabled', () => <Disabled action={action} />)
.add('Base Pre-defined Options Only', () => (
<PredefinedOptionsOnly action={action} />
))
.add('Inline Single Selection', () => <InlineSingle action={action} />)
.add('Inline Single Entity Selection', () => (
<InlineSingleEntityCombobox action={action} />
))
.add('Inline Single Search/Add Entities', () => (
<InlineSingleSearchAddEntities action={action} />
))
.add('Inline Multiple Selection', () => <InlineMultiple action={action} />)
.add('Inline Multiple Selection Loading', () => (
<InlineMultipleLoading action={action} />
))
.add('Base Custom Menu Item', () => <BaseCustomMenuItem action={action} />)
.add('Base Menu Sub Headers', () => <BaseMenuSubHeader action={action} />)
.add('Base Menu Separator', () => <BaseMenuSeparator action={action} />)
Expand Down Expand Up @@ -107,4 +125,14 @@ storiesOf(COMBOBOX, module)
))
.add('Snapshot Readonly Single Selection Custom Menu Item', () => (
<SnapshotReadonlySingleSelectionCustomMenuItemOpen action={action} />
))
.add('Snapshot Base Disabled', () => <SnapshotBaseDisabled action={action} />)
.add('Snapshot Inline Single Search/Add Entities Open', () => (
<SnapshotInlineSingleSearchAddEntitiesOpen action={action} />
))
.add('Snapshot Inline Single Entity Selection', () => (
<SnapshotInlineSingleEntityCombobox action={action} />
))
.add('Snapshot Inline Multiple Open Loading', () => (
<SnapshotInlineMultipleOpenLoading action={action} />
));
102 changes: 102 additions & 0 deletions components/combobox/__examples__/disabled.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/* eslint-disable no-console, react/prop-types */
import React from 'react';
import Combobox from '~/components/combobox';
import Icon from '~/components/icon';
import comboboxFilterAndLimit from '~/components/combobox/filter';
import IconSettings from '~/components/icon-settings';

const accounts = [
{
id: '1',
label: 'Acme',
subTitle: 'Account • San Francisco',
type: 'account',
},
{
id: '2',
label: 'Salesforce.com, Inc.',
subTitle: 'Account • San Francisco',
type: 'account',
},
{
id: '3',
label: "Paddy's Pub",
subTitle: 'Account • Boston, MA',
type: 'account',
},
{
id: '4',
label: 'Tyrell Corp',
subTitle: 'Account • San Francisco, CA',
type: 'account',
},
{
id: '5',
label: 'Paper St. Soap Company',
subTitle: 'Account • Beloit, WI',
type: 'account',
},
{
id: '6',
label: 'Nakatomi Investments',
subTitle: 'Account • Chicago, IL',
type: 'account',
},
{ id: '7', label: 'Acme Landscaping', subTitle: '\u00A0', type: 'account' },
{
id: '8',
label: 'Acme Construction',
subTitle: 'Account • Grand Marais, MN',
type: 'account',
},
];

const accountsWithIcon = accounts.map((elem) => ({
...elem,
...{
icon: (
<Icon
assistiveText={{ label: 'Account' }}
category="standard"
name={elem.type}
/>
),
},
}));

class Example extends React.Component {
constructor(props) {
super(props);

this.state = {
inputValue: '',
selection: [],
};
}

render() {
return (
<IconSettings iconPath="/assets/icons">
<Combobox
id="combobox-unique-id"
labels={{
label: 'Search',
placeholder: 'Search Salesforce',
}}
options={comboboxFilterAndLimit({
inputValue: this.state.inputValue,
limit: 10,
options: accountsWithIcon,
selection: this.state.selection,
})}
selection={this.state.selection}
value={this.state.inputValue}
disabled
/>
</IconSettings>
);
}
}

Example.displayName = 'ComboboxExample';
export default Example; // export is replaced with `ReactDOM.render(<Example />, mountNode);` at runtime
152 changes: 152 additions & 0 deletions components/combobox/__examples__/inline-multiple-loading.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
/* eslint-disable no-console, react/prop-types */
import React from 'react';
import Combobox from '~/components/combobox';
import Icon from '~/components/icon';
import comboboxFilterAndLimit from '~/components/combobox/filter';
import IconSettings from '~/components/icon-settings';

const accounts = [
{
id: '1',
label: 'Acme',
subTitle: 'Account • San Francisco',
type: 'account',
},
{
id: '2',
label: 'Salesforce.com, Inc.',
subTitle: 'Account • San Francisco',
type: 'account',
},
{
id: '3',
label: "Paddy's Pub",
subTitle: 'Account • Boston, MA',
type: 'account',
},
{
id: '4',
label: 'Tyrell Corp',
subTitle: 'Account • San Francisco, CA',
type: 'account',
},
{
id: '5',
label: 'Paper St. Soap Company',
subTitle: 'Account • Beloit, WI',
type: 'account',
},
{
id: '6',
label: 'Nakatomi Investments',
subTitle: 'Account • Chicago, IL',
type: 'account',
},
{ id: '7', label: 'Acme Landscaping', type: 'account' },
{
id: '8',
label: 'Acme Construction',
subTitle: 'Account • Grand Marais, MN',
type: 'account',
},
];

const accountsWithIcon = accounts.map((elem) => ({
...elem,
...{
icon: (
<Icon
assistiveText={{ label: 'Account' }}
category="standard"
name={elem.type}
/>
),
},
}));

class Example extends React.Component {
constructor(props) {
super(props);

this.state = {
inputValue: '',
selection: [],
};
}

render() {
return (
<IconSettings iconPath="/assets/icons">
<Combobox
id="combobox-unique-id"
events={{
onChange: (event, { value }) => {
this.props.action('onChange')(event, value);
this.setState({ inputValue: value });
},
onRequestRemoveSelectedOption: (event, data) => {
this.setState({
inputValue: '',
selection: data.selection,
});
},
onSubmit: (event, { value }) => {
if (this.props.action) {
this.props.action('onChange')(event, value);
} else if (console) {
console.log('onChange', event, value);
}
this.setState({
inputValue: '',
selection: [
...this.state.selection,
{
label: value,
icon: (
<Icon
assistiveText="Account"
category="standard"
name="account"
/>
),
},
],
});
},
onSelect: (event, data) => {
if (this.props.action) {
this.props.action('onSelect')(
event,
...Object.keys(data).map((key) => data[key])
);
} else if (console) {
console.log('onSelect', event, data);
}
this.setState({
inputValue: '',
selection: data.selection,
});
},
}}
labels={{
label: 'Search',
placeholder: 'Search Salesforce',
}}
multiple
options={comboboxFilterAndLimit({
inputValue: this.state.inputValue,
options: accountsWithIcon,
selection: this.state.selection,
})}
selection={this.state.selection}
value={this.state.inputValue}
variant="inline-listbox"
loading
/>
</IconSettings>
);
}
}

Example.displayName = 'ComboboxExample';
export default Example; // export is replaced with `ReactDOM.render(<Example />, mountNode);` at runtime
Loading