Skip to content

Commit

Permalink
CDC #204 - Adding ability to pass arbitrary buttons to AssociatedDrop…
Browse files Browse the repository at this point in the history
…down component
  • Loading branch information
dleadbetter committed May 9, 2024
1 parent 92e7675 commit 903f14d
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
13 changes: 13 additions & 0 deletions packages/semantic-ui/src/components/AssociatedDropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ class AssociatedDropdown extends Component<Props, State> {
{ this.renderEditButton() }
{ this.renderAddButton() }
{ this.renderClearButton() }
{ this.renderButtons() }
</Button.Group>
{ this.renderModal() }
{ this.state.saved && (
Expand Down Expand Up @@ -284,6 +285,18 @@ class AssociatedDropdown extends Component<Props, State> {
);
}

/**
* Renders the extra buttons.
*
* @returns {*}
*/
renderButtons() {
const excludeButtons = [BUTTON_ADD, BUTTON_CLEAR, BUTTON_EDIT];
const buttons = _.filter(this.props.buttons, (button) => !excludeButtons.includes(button.name));

return _.map(buttons, (button) => this.renderButton(button.name, _.omit(button, 'name')));
}

/**
* Renders the clear button.
*
Expand Down
38 changes: 38 additions & 0 deletions packages/storybook/src/semantic-ui/AssociatedDropdown.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -465,3 +465,41 @@ export const CustomButtons = () => (
upward={boolean('Open upward', false)}
/>
);

export const AdditionalButtons = () => (
<AssociatedDropdown
buttons={[{
name: 'add',
}, {
name: 'clear',
}, {
basic: true,
name: 'navigate',
content: 'Navigate',
icon: 'world',
onClick: action('navigate'),
type: 'button'
}]}
collectionName='items'
modal={{
component: AddModal,
props: {
onInitialize: () => Promise.resolve({ })
},
onSave: () => {
action('save')();
return Promise.resolve({});
}
}}
onSearch={(search) => Api.onLoad({ items, search, sort_by: 'text' })}
onSelection={action('selection')}
placeholder={text('Placeholder', 'Search')}
renderOption={(item) => ({
key: item.id,
value: item.id,
text: item.company,
description: item.country
})}
upward={boolean('Open upward', false)}
/>
);

0 comments on commit 903f14d

Please sign in to comment.