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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cv-text-input-skeleton): add CvTextInputSkeleton #1542

Merged
Merged
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
25 changes: 24 additions & 1 deletion src/components/CvTextInput/CvTextInput.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
storyParametersObject,
} from '../../global/storybook-utils';

import CvTextInput from '.';
import { CvTextInput, CvTextInputSkeleton } from '.';
import { ref } from 'vue';

export default {
Expand Down Expand Up @@ -243,3 +243,26 @@ Password.parameters = storyParametersObject(
template,
Password.args
);

const templateSkeleton = `<cv-text-input-skeleton v-bind='args'/>`;
const TemplateSkeleton = args => {
return {
components: { CvTextInputSkeleton },
setup: () => ({ args }),
template: templateSkeleton,
};
};

export const Skeleton = TemplateSkeleton.bind({});

Skeleton.parameters = {
controls: {
include: ['hideLabel'],
},
};

Skeleton.parameters = storyParametersObject(
Skeleton.parameters,
templateSkeleton,
Skeleton.args
);
17 changes: 17 additions & 0 deletions src/components/CvTextInput/CvTextInputSkeleton.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<template>
<div :class="[`${carbonPrefix}--form-item`]">
<span
v-if="!hideLabel"
:class="[`${carbonPrefix}--label`, `${carbonPrefix}--skeleton`]"
></span>
<div
:class="[`${carbonPrefix}--text-input`, `${carbonPrefix}--skeleton`]"
></div>
</div>
</template>

<script setup>
import { carbonPrefix } from '../../global/settings';

defineProps({ hideLabel: { type: Boolean, default: false } });
</script>
44 changes: 43 additions & 1 deletion src/components/CvTextInput/__tests__/CvTextInput.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { render } from '@testing-library/vue';
import userEvent from '@testing-library/user-event';
import CvTextInput from '..';
import { CvTextInput, CvTextInputSkeleton } from '..';

describe('CvTextInput', () => {
it("renders label when 'label' prop is passed", () => {
Expand Down Expand Up @@ -459,3 +459,45 @@ describe('CvTextInput', () => {
});
});
});

describe('CvTextInputSkeleton', () => {
it("renders label when 'hideLabel' prop is omitted", async () => {
const skeleton = render(CvTextInputSkeleton);
const label = skeleton.container.querySelector(
'span.bx--label.bx--skeleton'
);
expect(label).toBeTruthy();
});
it("renders label when 'hideLabel' prop is false", async () => {
const skeleton = render(CvTextInputSkeleton, {
props: { hideLabel: false },
});
const label = skeleton.container.querySelector(
'span.bx--label.bx--skeleton'
);
expect(label).toBeTruthy();
});
it("does not render label when 'hideLabel' prop is true", async () => {
const skeleton = render(CvTextInputSkeleton, {
props: { hideLabel: true },
});
const label = skeleton.container.querySelector(
'span.bx--label.bx--skeleton'
);
expect(label).toBeFalsy();
});
it('renders div with correct class', async () => {
const skeleton = render(CvTextInputSkeleton);
const div = skeleton.container.querySelector(
'div.bx--text-input.bx--skeleton'
);
expect(div).toBeTruthy();
});
it('is accessible', async () => {
const main = document.createElement('main');
const skeleton = render(CvTextInputSkeleton, {
container: document.body.appendChild(main),
});
await expect(skeleton.container).toBeAccessible('cv-text-input-skeleton');
}, 10000);
});
3 changes: 2 additions & 1 deletion src/components/CvTextInput/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import CvTextInput from './CvTextInput.vue';
import CvTextInputSkeleton from './CvTextInputSkeleton.vue';

export { CvTextInput };
export { CvTextInput, CvTextInputSkeleton };
export default CvTextInput;
Loading