Skip to content

Commit

Permalink
feat: Additional content slot in Collection Preferences (#3124)
Browse files Browse the repository at this point in the history
Co-authored-by: Ernst Kaese <[email protected]>
Co-authored-by: Gethin Webster <[email protected]>
  • Loading branch information
3 people authored Jan 3, 2025
1 parent 5fd71dd commit e66864b
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 2 deletions.
11 changes: 11 additions & 0 deletions pages/collection-preferences/simple.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// SPDX-License-Identifier: Apache-2.0
import * as React from 'react';

import Alert from '~components/alert';
import Box from '~components/box';
import CollectionPreferences from '~components/collection-preferences';

import ScreenshotArea from '../utils/screenshot-area';
Expand Down Expand Up @@ -29,6 +31,15 @@ export default function CollectionPreferencesPermutations() {
visibleContentPreference={visibleContentPreference}
stickyColumnsPreference={stickyColumnsPreference}
customPreference={customPreference}
contentBefore={
<Box margin={{ bottom: 's' }}>
<Alert type={'warning'} header={'Local storage not enabled'}>
Go to your browser settings to enable local storage. This will persist your settings across sessions
unless your local storage is cleared. If local storage is not enabled preferences are saved in session
storage as a fallback.
</Alert>
</Box>
}
/>
<CollectionPreferences className={`cp-2`} {...baseProperties} customPreference={customPreference} />
<CollectionPreferences
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5667,7 +5667,13 @@ You must set the current value in the \`preferences.wrapLines\` property.",
"type": "CollectionPreferencesProps.WrapLinesPreference",
},
],
"regions": [],
"regions": [
{
"description": "Content displayed before the preferences. Use it to display additional information relating to the preferences.",
"isDefault": false,
"name": "contentBefore",
},
],
"releaseStatus": "stable",
}
`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ exports[`test-utils selectors 1`] = `
"collection-preferences": [
"awsui_cancel-button_tc96w",
"awsui_confirm-button_tc96w",
"awsui_content-before_tc96w",
"awsui_content-density_tc96w",
"awsui_content-display-description_tc96w",
"awsui_content-display-no-match_tc96w",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,13 @@ describe('Collection preferences - Modal', () => {
wrapper.findModal()!.findConfirmButton()!.click();
expectVisibleModal(wrapper, false);
});
test('is additional content displayed when provided', () => {
const wrapper = renderCollectionPreferences({
contentBefore: 'Test content before',
});
wrapper.findTriggerButton().click();
expect(wrapper.findModal()!.findContentBefore()?.getElement().textContent).toBe('Test content before');
});
});

describe('Collection preferences - Events', () => {
Expand Down
5 changes: 5 additions & 0 deletions src/collection-preferences/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export default function CollectionPreferences({
customPreference,
getModalRoot,
removeModalRoot,
contentBefore,
...rest
}: CollectionPreferencesProps) {
const parentMetadata = useContext(CollectionPreferencesMetadata);
Expand Down Expand Up @@ -181,6 +182,10 @@ export default function CollectionPreferences({
size={hasContentOnTheLeft && hasContentOnTheRight ? 'large' : 'medium'}
onDismiss={onCancelListener}
>
{/* Content before */}
<div className={styles['content-before']}>{contentBefore}</div>

{/* Preferences content */}
<ModalContentLayout
left={
hasContentOnTheLeft && (
Expand Down
4 changes: 4 additions & 0 deletions src/collection-preferences/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,10 @@ export interface CollectionPreferencesProps<CustomPreferenceType = any> extends
* The values for all configured preferences are present even if the user didn't change their values.
*/
onConfirm?: NonCancelableEventHandler<CollectionPreferencesProps.Preferences<CustomPreferenceType>>;
/**
* Content displayed before the preferences. Use it to display additional information relating to the preferences.
*/
contentBefore?: React.ReactNode;
}

export namespace CollectionPreferencesProps {
Expand Down
3 changes: 2 additions & 1 deletion src/collection-preferences/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
.trigger-button,
.cancel-button,
.confirm-button,
.custom {
.custom,
.content-before {
/* used in test-utils */
}

Expand Down
4 changes: 4 additions & 0 deletions src/test-utils/dom/collection-preferences/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ class PreferencesModalWrapper extends ModalWrapper {
findCustomPreference(): ElementWrapper | null {
return this.findByClassName(styles.custom);
}

findContentBefore(): ElementWrapper | null {
return this.findByClassName(styles['content-before']);
}
}

export default class CollectionPreferencesWrapper extends ComponentWrapper {
Expand Down

0 comments on commit e66864b

Please sign in to comment.