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

[BD-7115] Add Section Header into Backpack #2912

Merged
merged 14 commits into from
Jul 17, 2023
Merged

Conversation

KathyWang0208
Copy link
Contributor

@KathyWang0208 KathyWang0208 commented Jul 12, 2023

###Changes
Figma link

Add backpack section header component

###Snapshots

Default

Default RTL

With description

Default RTL

With Full props

Default RTL

image

Remember to include the following changes:

  • README.md (If you have created a new component)
  • Component README.md
  • Tests
  • Storybook examples created/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

@KathyWang0208 KathyWang0208 changed the title Build Section Header [BD-7115] Build Section Header Jul 12, 2023
@github-actions
Copy link

github-actions bot commented Jul 12, 2023

Browser support

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

Generated by 🚫 dangerJS against 1ac15d6

@github-actions
Copy link

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

@KathyWang0208 KathyWang0208 added the major Breaking change label Jul 12, 2023
@github-actions
Copy link

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

@KathyWang0208 KathyWang0208 added minor Non breaking change and removed major Breaking change labels Jul 12, 2023
@KathyWang0208 KathyWang0208 changed the title [BD-7115] Build Section Header [BD-7115] Add Section Header into Backpack Jul 12, 2023
@github-actions
Copy link

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

Copy link
Contributor

@anambl anambl left a comment

Choose a reason for hiding this comment

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

Only other thing if you could please remove the flow tags as we don't need those anymore now that you've changed it to TS! 😄

.bpk-component-section-header {
&--btn {
display: flex;
width: 36 * $bpk-one-pixel-rem;
Copy link
Contributor

Choose a reason for hiding this comment

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

You don't need this, as button has a iconOnly prop so you don't need to set the width/height yourself 😄

<BpkButton
className={cls('bpk-component-section-header--btn')}
CommonProps={{ blank: false }}
>
Copy link
Contributor

Choose a reason for hiding this comment

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

What is this prop used for?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

if missing it, got this warning
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.

should I remove CommonProps?

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh that's weird.. actually BpkButton is not written in TS. Instead you can use BpkButtonV2 which is the newer version and is written in TS as the old one will go away anyways 🙂
import { BpkButtonV2 } from '../../packages/bpk-component-button';

Copy link
Contributor

Choose a reason for hiding this comment

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

CommonProps is not actually a prop, I guess the TS compiler gets a bit confused with importing a JS component into a TS 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.

BpkButtonV2 works, thank you


import STYLES from './examples.module.scss';

const cls = cssModules(STYLES);
Copy link
Contributor

Choose a reason for hiding this comment

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

could you rename this to getClassName just to align with the rest of the usages


export const ForMobile = MobileExample;

export const VisualTestDefault = DefaultExample;
Copy link
Contributor

Choose a reason for hiding this comment

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

No need to have a visual test for each of these. Instead you can bundle them all into one example component that gets visually tested. We do this in most of our components for example - https://github.com/Skyscanner/backpack/blob/main/examples/bpk-component-badge/examples.js#L140

justify-content: space-between;
align-items: flex-start;

&--titleAndDesc {
Copy link
Contributor

Choose a reason for hiding this comment

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

can you rename this so that it uses kebab case for consistency? We don't use camel case

@github-actions
Copy link

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


/* @flow strict */

import { get } from 'lodash';
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this is used?

| --------------------- |----------|----------| ------------- |
| title | string | true | - |
| description | string | false | - |
| button | node | false | - |
Copy link
Contributor

Choose a reason for hiding this comment

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

can you also add the onDark prop here please? 😄

@anambl
Copy link
Contributor

anambl commented Jul 13, 2023

Can you also add the type declaration files d.ts and remove the flow tags? 😄
For the type declaration files you can use the TS compiler to autogenerate them!

@import '~bpk-mixins/index.scss';

.bpk-section-header-examples {
&--on-dark {
Copy link
Contributor

Choose a reason for hiding this comment

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

If this is the first level, could use &__on-dark like many other cases in backpack.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for reviews, &--on-dark is acceptable like BpkModalInner.module.scss


&--mixed {
display: flex;
grid-row-gap: $bpk-spacing-base;
Copy link
Contributor

Choose a reason for hiding this comment

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

Use bpk-spacing-base()

* limitations under the License.
*/

/* @flow strict */
Copy link
Contributor

Choose a reason for hiding this comment

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

I think if changed into typescript, this kind of exegesis could be removed.

| title | string | true | - |
| description | string | false | - |
| button | node | false | - |
| type | oneOf("default", "onDark") | false | default |
Copy link
Contributor

Choose a reason for hiding this comment

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

Should be SECTION_TYPES.onDark and SECTION_TYPES.default

<BpkSectionHeader
title="Section title"
description="Section title description"
button={<BpkButton onClick={() => jest.fn()}>View more</BpkButton>}
Copy link
Contributor

Choose a reason for hiding this comment

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

Use BpkButtonV2 here to keep consistency?

@github-actions
Copy link

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

@github-actions
Copy link

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

* limitations under the License.
*/

/* @flow strict */
Copy link
Contributor

Choose a reason for hiding this comment

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

All of this should be deleted since you are already using TypeScript for the type checking but not Flow

<div
className={getClassName(
'bpk-section-header',
onDark && 'bpk-section-header--on-dark',
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
onDark && 'bpk-section-header--on-dark',
`bpk-section-header--${SECTION_TYPES}`,
&--default {
  color: $bpk-text-primary-day;
}

&--onDark {
    color: $bpk-text-on-dark-day;
  }

This will make it look more concise

<div
className={getClassName(
'bpk-section-header--title-description',
onDark && 'bpk-section-header--title-description--on-dark',
Copy link
Contributor

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 27 to 31
it('should not have programmatically-detectable accessibility issues', async () => {
const { container } = render(<BpkSectionHeader title="Section title" />);
const results = await axe(container);
expect(results).toHaveNoViolations();
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe you can also add a new one for including description?

<div
className={getClassName(
'bpk-section-header',
onDark && 'bpk-section-header--on-dark',
Copy link
Contributor

Choose a reason for hiding this comment

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

how about simply use 'bpk-section-header--dark'

Copy link
Contributor Author

@KathyWang0208 KathyWang0208 Jul 14, 2023

Choose a reason for hiding this comment

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

yes, I changed the onDark value as on-dark, and use bpk-section-header--on-dark

}: Props) => {
const onDark = type === SECTION_TYPES.onDark;
return (
<div
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we support Accessibility in this component

Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps we could add another prop as a label for the button? I don't think that the aria-label for text is needed as it's text and not an interactive element?

Copy link
Contributor Author

@KathyWang0208 KathyWang0208 Jul 14, 2023

Choose a reason for hiding this comment

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

button is a node, can we deal with the accessibility for it in the consumed micosite, then we don't need one more prop.

Copy link
Contributor

@anambl anambl Jul 14, 2023

Choose a reason for hiding this comment

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

@Supremeyh any thoughts from an accessibility perspective on what could be improved? 🙂
From my perspective the text elements should be fine as they are and do not need a label as labels should be used for interactive elements. The texts gets read out by screen readers. Button like Kathy said should be handled on the microsite

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks @anambl and @KathyWang0208! It's great to hear that the text elements are already accessible, and interactive elements button can also support on microsite side. In this case, it's fine to me.

@github-actions
Copy link

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

@github-actions
Copy link

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

@github-actions
Copy link

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

@anambl anambl merged commit b729f69 into main Jul 17, 2023
7 checks passed
@anambl anambl deleted the BD-7115-BPK-section-header branch July 17, 2023 08:39
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.

6 participants