Skip to content

Commit

Permalink
feat: adding hideCloseButton prop to cv-inline-notification (#1233)
Browse files Browse the repository at this point in the history
Co-authored-by: Luiza <luizaleitemendes@ibm.com>
Co-authored-by: Lee Chase <leechase@live.com>
  • Loading branch information
3 people authored Aug 16, 2021
1 parent dc3d8e1 commit fd41a30
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,5 +1,65 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`CvInlineNotification should not render close button when hideCloseButton is true 1`] = `
<div data-notification="" role="alert" class="cv-inline-notification bx--inline-notification bx--inline-notification--error">
<div class="bx--inline-notification__details">
<anonymous-stub class="bx--inline-notification__icon"></anonymous-stub>
<div class="bx--inline-notification__text-wrapper">
<p class="bx--inline-notification__title"></p>
<p class="bx--inline-notification__subtitle"></p>
</div>
</div> <button type="button" class="bx--inline-notification__action-button bx--btn bx--btn--sm bx--btn--ghost">
test action label
</button>
<!---->
</div>
`;

exports[`CvInlineNotification should not render close button when hideCloseButton is true 2`] = `
<div data-notification="" aria-live="polite" class="cv-inline-notification bx--inline-notification bx--inline-notification--info">
<div class="bx--inline-notification__details">
<anonymous-stub class="bx--inline-notification__icon"></anonymous-stub>
<div class="bx--inline-notification__text-wrapper">
<p class="bx--inline-notification__title"></p>
<p class="bx--inline-notification__subtitle"></p>
</div>
</div> <button type="button" class="bx--inline-notification__action-button bx--btn bx--btn--sm bx--btn--ghost">
test action label
</button>
<!---->
</div>
`;

exports[`CvInlineNotification should not render close button when hideCloseButton is true 3`] = `
<div data-notification="" role="alert" class="cv-inline-notification bx--inline-notification bx--inline-notification--warning">
<div class="bx--inline-notification__details">
<anonymous-stub class="bx--inline-notification__icon"></anonymous-stub>
<div class="bx--inline-notification__text-wrapper">
<p class="bx--inline-notification__title"></p>
<p class="bx--inline-notification__subtitle"></p>
</div>
</div> <button type="button" class="bx--inline-notification__action-button bx--btn bx--btn--sm bx--btn--ghost">
test action label
</button>
<!---->
</div>
`;

exports[`CvInlineNotification should not render close button when hideCloseButton is true 4`] = `
<div data-notification="" aria-live="polite" class="cv-inline-notification bx--inline-notification bx--inline-notification--success">
<div class="bx--inline-notification__details">
<anonymous-stub class="bx--inline-notification__icon"></anonymous-stub>
<div class="bx--inline-notification__text-wrapper">
<p class="bx--inline-notification__title"></p>
<p class="bx--inline-notification__subtitle"></p>
</div>
</div> <button type="button" class="bx--inline-notification__action-button bx--btn bx--btn--sm bx--btn--ghost">
test action label
</button>
<!---->
</div>
`;

exports[`CvInlineNotification should render correctly 1`] = `
<div data-notification="" role="alert" class="cv-inline-notification bx--inline-notification bx--inline-notification--error">
<div class="bx--inline-notification__details">
Expand Down
11 changes: 10 additions & 1 deletion packages/core/__tests__/cv-inline-notification.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe('CvInlineNotification', () => {
// ***************
// PROP CHECKS
// ***************
testComponent.propsAreType(CvInlineNotification, ['lowContrast'], Boolean);
testComponent.propsAreType(CvInlineNotification, ['lowContrast', 'hideCloseButton'], Boolean);
testComponent.propsAreType(CvInlineNotification, ['actionLabel', 'closeAriaLabel', 'kind'], String);
testComponent.propsHaveDefault(CvInlineNotification, ['closeAriaLabel', 'kind', 'actionLabel']);

Expand Down Expand Up @@ -56,6 +56,15 @@ describe('CvInlineNotification', () => {
}
});

it('should not render close button when hideCloseButton is true', async () => {
const propsData = { lowContrast: false, kind: '', actionLabel: 'test action label', hideCloseButton: true };
for (const kind of kinds) {
propsData.kind = kind;
const wrapper = await shallow(CvInlineNotification, { propsData });
expect(wrapper.html()).toMatchSnapshot();
}
});

// ***************
// FUNCTIONAL TESTS
// ***************
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
{{ actionLabel }}
</button>
<button
v-if="!hideCloseButton"
type="button"
:aria-label="closeAriaLabel"
data-notification-btn
Expand Down Expand Up @@ -66,6 +67,7 @@ export default {
validator: val => ['error', 'info', 'warning', 'success'].includes(val),
},
lowContrast: Boolean,
hideCloseButton: Boolean,
},
computed: {
icon() {
Expand Down
6 changes: 6 additions & 0 deletions storybook/stories/cv-inline-notification-story.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ const preKnobs = {
config: ['Low contrast', false],
prop: 'low-contrast',
},
hideCloseButton: {
group: 'attr',
type: boolean,
config: ['Hide close button', false],
prop: 'hide-close-button',
},
};

const variants = [
Expand Down

0 comments on commit fd41a30

Please sign in to comment.