-
Notifications
You must be signed in to change notification settings - Fork 183
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
[MAT-1205] [BpkSkeleton] Add new component - bpk-component-skeleton #3337
Conversation
Browser supportIf this is a visual change, make sure you've tested it in multiple browsers. |
Visit https://backpack.github.io/storybook-prs/3337 to see this build running in a browser. |
Visit https://backpack.github.io/storybook-prs/3337 to see this build running in a browser. |
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>
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>
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>
Visit https://backpack.github.io/storybook-prs/3337 to see this build running in a browser. |
Visit https://backpack.github.io/storybook-prs/3337 to see this build running in a browser. |
<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" | ||
/> |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated.
const classNames = [getClassName('bpk-skeleton')]; | ||
if (className) { | ||
classNames.push(className); | ||
} |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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} /> |
There was a problem hiding this comment.
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}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated.
type Props = { | ||
className: string; | ||
ariaLabel?: string; | ||
styleObj?: { | ||
width: string; | ||
height: string; | ||
}; | ||
}; | ||
|
||
const BpkBaseSkeleton = ({ | ||
ariaLabel, | ||
className, | ||
styleObj | ||
}: Props) => { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated.
ariaLabel, | ||
className, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here
ariaLabel, | ||
className, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here
ariaLabel, | ||
className, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same above
ariaLabel, | ||
className, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same above
Visit https://backpack.github.io/storybook-prs/3337 to see this build running in a browser. |
Visit https://backpack.github.io/storybook-prs/3337 to see this build running in a browser. |
Visit https://backpack.github.io/storybook-prs/3337 to see this build running in a browser. |
Visit https://backpack.github.io/storybook-prs/3337 to see this build running in a browser. |
Visit https://backpack.github.io/storybook-prs/3337 to see this build running in a browser. |
Visit https://backpack.github.io/storybook-prs/3337 to see this build running in a browser. |
…github.com/Skyscanner/backpack into MAT-1205_implment_skeleton_with_fully_test
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; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
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')); | ||
} | ||
} |
There was a problem hiding this comment.
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
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; |
There was a problem hiding this comment.
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.
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]; | ||
}; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
Visit https://backpack.github.io/storybook-prs/3337 to see this build running in a browser. |
Visit https://backpack.github.io/storybook-prs/3337 to see this build running in a browser. |
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, | ||
} |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Visit https://backpack.github.io/storybook-prs/3337 to see this build running in a browser. |
…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>
…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>
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:
[KOA-123][BpkButton] Updating the colour
README.md
(If you have created a new component)README.md
.d.ts
) files updated