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

[MAT-1205] [BpkSkeleton] Add new component - bpk-component-skeleton #3337

Merged
merged 28 commits into from
Apr 24, 2024

Conversation

felix-luo-sc
Copy link
Contributor

@felix-luo-sc felix-luo-sc commented Apr 7, 2024

Add new component - bpk-component-skeleton

Figma

https://www.figma.com/file/irZ3YBx8vOm16ICkAr7mB3/Backpack-Components?type=design&node-id=18542-18065&mode=design&t=uAl9OPzRHO5BX3Wy-0

This component can be viewed here: https://backpack.github.io/storybook-prs/3337/?path=/docs/bpk-component-skeleton--documentation

Remember to include the following changes:

  • Ensure the PR title includes the name of the component you are changing so it's clear in the release notes for consumers of the changes in the version e.g [KOA-123][BpkButton] Updating the colour
  • README.md (If you have created a new component)
  • Component README.md
  • Tests
  • Storybook examples created/updated
  • Type declaration (.d.ts) files updated
  • For breaking changes or deprecating components/properties, migration guides added to the description of the PR. If the guide has large changes, consider creating a new Markdown page inside the component's docs folder and link it here

Copy link

github-actions bot commented Apr 7, 2024

Warnings
⚠️

Package source files (e.g. packages/package-name/src/Component.js) were updated, but snapshots weren't. Have you checked that the tests still pass?

⚠️

Package source files (e.g. packages/package-name/src/Component.tsx) were updated, but type files weren't. Have you checked that no types have changed?

Browser support

If this is a visual change, make sure you've tested it in multiple browsers.

Generated by 🚫 dangerJS against a7b8095

Copy link

github-actions bot commented Apr 7, 2024

Visit https://backpack.github.io/storybook-prs/3337 to see this build running in a browser.

@felix-luo-sc felix-luo-sc added the minor Non breaking change label Apr 8, 2024
Copy link

github-actions bot commented Apr 8, 2024

Visit https://backpack.github.io/storybook-prs/3337 to see this build running in a browser.

Copy link

github-actions bot commented Apr 8, 2024

Visit https://backpack.github.io/storybook-prs/3337 to see this build running in a browser.

* add test file

* add accessibility test

---------

Co-authored-by: Felix luo <felix.luo@skyscanner.net>
Copy link

github-actions bot commented Apr 9, 2024

Visit https://backpack.github.io/storybook-prs/3337 to see this build running in a browser.

Co-authored-by: Felix luo <felix.luo@skyscanner.net>
Copy link

github-actions bot commented Apr 9, 2024

Visit https://backpack.github.io/storybook-prs/3337 to see this build running in a browser.

Co-authored-by: Felix luo <felix.luo@skyscanner.net>
Copy link

github-actions bot commented Apr 9, 2024

Visit https://backpack.github.io/storybook-prs/3337 to see this build running in a browser.

Copy link

github-actions bot commented Apr 9, 2024

Visit https://backpack.github.io/storybook-prs/3337 to see this build running in a browser.

@felix-luo-sc felix-luo-sc changed the title [MAT-1205] implement skeleton [MAT-1205] [BpkSkeleton] Add new component - bpk-component-skeleton Apr 9, 2024
@olliecurtis olliecurtis self-assigned this Apr 9, 2024
Comment on lines 22 to 44
<BpkImageSkeleton
style={IMAGE_SKELETON_STYLE.rounded}
size={{width: '7rem', height: '6rem'}}
ariaLabel="loading"
/>

<BpkBodyTextSkeleton
size={SIZE_TYPES.large}
ariaLabel="loading"
className="custom-class"
/>

<BpkCircleSkeleton
size={SIZE_TYPES.small}
ariaLabel="loading"
className="custom-class"
/>

<BpkHeadlineSkeleton
size={SIZE_TYPES.small}
ariaLabel="loading"
className="custom-class"
/>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be a div wrapper here. What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, agree with you. Updated.

}
}

@keyframes shimmer-anim {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it better to write its name clearly here, such as shimmer-animation?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.

Comment on lines 40 to 43
const classNames = [getClassName('bpk-skeleton')];
if (className) {
classNames.push(className);
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this be simplified to const classNames = getClassName('bpk-skeleton', className)? What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.

}

return (
<div role="status" aria-label={ariaLabel} className={classNames.join(' ')} style={styleObj} />
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I think className={classNames.join(' ')} can be className={classNames}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.

Comment on lines 25 to 38
type Props = {
className: string;
ariaLabel?: string;
styleObj?: {
width: string;
height: string;
};
};

const BpkBaseSkeleton = ({
ariaLabel,
className,
styleObj
}: Props) => {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see that ariaLabel and styleObj are optional. So could we assign initial values to them?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.

Comment on lines 45 to 46
ariaLabel,
className,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

Comment on lines 44 to 45
ariaLabel,
className,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

Comment on lines 45 to 46
ariaLabel,
className,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same above

Comment on lines 50 to 51
ariaLabel,
className,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same above

Copy link

Visit https://backpack.github.io/storybook-prs/3337 to see this build running in a browser.

Copy link

Visit https://backpack.github.io/storybook-prs/3337 to see this build running in a browser.

Copy link

Visit https://backpack.github.io/storybook-prs/3337 to see this build running in a browser.

Copy link

Visit https://backpack.github.io/storybook-prs/3337 to see this build running in a browser.

Copy link

Visit https://backpack.github.io/storybook-prs/3337 to see this build running in a browser.

Copy link

Visit https://backpack.github.io/storybook-prs/3337 to see this build running in a browser.

Copy link

Visit https://backpack.github.io/storybook-prs/3337 to see this build running in a browser.

type ComponentProps = {
type: Extract<SkeletonType, 'image'>
size?: SizeMap['image'] | CUSTOM_SIZE_TYPE;
ariaLabel: string;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just speaking with A11y folks on this one we will not want to have an ariaLabel at all on this Skeleton component and actually the skeleton should be aria-hidden until it loads.

I have updated the API in the Figma design to reflect this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. Thank you for confirming. Let me update the pr.

Comment on lines 72 to 85
const classNames:string[] = [getClassName(`bpk-skeleton__${type}`)];
let styleObj;

if(typeof size === 'object') {
styleObj = size;
} else {
classNames.push(getClassName(`bpk-skeleton__${type}--${size}`))
}

if(type === SKELETON_TYPES.image) {
if(props.style === IMAGE_SKELETON_STYLE.rounded) {
classNames.push(getClassName('bpk-skeleton__image--rounded'));
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be simplified to be

Suggested change
const classNames:string[] = [getClassName(`bpk-skeleton__${type}`)];
let styleObj;
if(typeof size === 'object') {
styleObj = size;
} else {
classNames.push(getClassName(`bpk-skeleton__${type}--${size}`))
}
if(type === SKELETON_TYPES.image) {
if(props.style === IMAGE_SKELETON_STYLE.rounded) {
classNames.push(getClassName('bpk-skeleton__image--rounded'));
}
}
const isImageRounded = type === SKELETON_TYPES.image && props.style === IMAGE_SKELETON_STYLE.rounded
const classNames:string = getClassName(
`bpk-skeleton__${type}`,
typeof size != 'object' && `bpk-skeleton__${type}--${size}`,
isImageRounded && 'bpk-skeleton__image--rounded'
);
const styleObj = typeof size === 'object' ? size : null;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated. There is a little difference, if the type of size is not object, then styleObj is set to undefined. Because to set the style attribute to an element, it must be either object or undefined.

Comment on lines 29 to 57
export const SIZE_TYPES = {
small: 'small',
default: 'default',
large: 'large',
} as const;

export type SizeType = (typeof SIZE_TYPES)[keyof typeof SIZE_TYPES] | CUSTOM_SIZE_TYPE;

export const SKELETON_TYPES = {
image: 'image',
bodyText: 'bodyText',
circle: 'circle',
headline: 'headline',
} as const;

export type SkeletonType = (typeof SKELETON_TYPES)[keyof typeof SKELETON_TYPES];

export const IMAGE_SKELETON_STYLE = {
rounded: 'rounded',
default: 'default',
} as const;
export type ImageSkeletonStyle = (typeof IMAGE_SKELETON_STYLE)[keyof typeof IMAGE_SKELETON_STYLE];

type SizeMap = {
[SKELETON_TYPES.image]: (typeof SIZE_TYPES)['default'];
[SKELETON_TYPES.bodyText]: (typeof SIZE_TYPES)[keyof typeof SIZE_TYPES];
[SKELETON_TYPES.circle]: Exclude<(typeof SIZE_TYPES)[keyof typeof SIZE_TYPES], 'large'>
[SKELETON_TYPES.headline]: (typeof SIZE_TYPES)[keyof typeof SIZE_TYPES];
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thinking of these to make this file a bit more readable to place these inside the common-types.tsx file

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, just like what BpkButtonV2 does. Updated.

Copy link

Visit https://backpack.github.io/storybook-prs/3337 to see this build running in a browser.

Copy link

Visit https://backpack.github.io/storybook-prs/3337 to see this build running in a browser.

Copy link

Visit https://backpack.github.io/storybook-prs/3337 to see this build running in a browser.

BpkSkeleton.defaultProps = {
size: SIZE_TYPES.default,
style: IMAGE_SKELETON_STYLE.default,
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In TS we wouldn't declare default props like this but more up in the props definition on L31

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be this?
image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason why I don't deconstruct at line L31 is that it will cause ts error. (The style property only exist when type is 'image')
image

Copy link

Visit https://backpack.github.io/storybook-prs/3337 to see this build running in a browser.

@olliecurtis olliecurtis merged commit 594f25a into main Apr 24, 2024
9 checks passed
@olliecurtis olliecurtis deleted the MAT-1205_implment_skeleton_with_fully_test branch April 24, 2024 12:33
KathyWang0208 pushed a commit that referenced this pull request May 27, 2024
…3337)

* implement skeleton

* add declare file

* [MAT-1241] add test files (#3340)

* add test file

* add accessibility test

---------

Co-authored-by: Felix luo <felix.luo@skyscanner.net>

* update examples and stories (#3341)

Co-authored-by: Felix luo <felix.luo@skyscanner.net>

* update readme file (#3342)

Co-authored-by: Felix luo <felix.luo@skyscanner.net>

* add role for base skeleton component

* optimize code and remove visual test

* update lint

* add a combined component example

* Refactored the code (#3352)

Co-authored-by: Felix luo <felix.luo@skyscanner.net>

* rename className to skeletonStyle

* update test

* update scss

* update examples

* use vertical style on examples

* remove ariaLabel, simplify bpkskeleton and categorize types

* update readme

* change the declare of default value

---------

Co-authored-by: Felix luo <felix.luo@skyscanner.net>
KathyWang0208 pushed a commit that referenced this pull request May 27, 2024
…3337)

* implement skeleton

* add declare file

* [MAT-1241] add test files (#3340)

* add test file

* add accessibility test

---------

Co-authored-by: Felix luo <felix.luo@skyscanner.net>

* update examples and stories (#3341)

Co-authored-by: Felix luo <felix.luo@skyscanner.net>

* update readme file (#3342)

Co-authored-by: Felix luo <felix.luo@skyscanner.net>

* add role for base skeleton component

* optimize code and remove visual test

* update lint

* add a combined component example

* Refactored the code (#3352)

Co-authored-by: Felix luo <felix.luo@skyscanner.net>

* rename className to skeletonStyle

* update test

* update scss

* update examples

* use vertical style on examples

* remove ariaLabel, simplify bpkskeleton and categorize types

* update readme

* change the declare of default value

---------

Co-authored-by: Felix luo <felix.luo@skyscanner.net>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
minor Non breaking change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants