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

feature: Accordion component #189

Closed
wants to merge 6 commits into from
Closed

Conversation

consolecmnd
Copy link

@consolecmnd consolecmnd commented Apr 30, 2024

My first StoryBook component so there will be missing details.

Improvements:

ReducedMotion
Currently using @media styles and not const { prefersReducedMotion } = useUserPrefs()

Icon Component
I don't think it's implemented it correctly

ReadMe
Possibly lacking detail

TS
Guessing Typescript implementation isn't perfect

Responsiveness
Accordion height updated on click, not window resize

Takes strings or objects and wraps in < p >. More content design thought needed here

Remove DEFAULT_TAG? Seems verbose for how it's used here

Copy link

changeset-bot bot commented Apr 30, 2024

⚠️ No Changeset found

Latest commit: 6ac5d15

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@marlonmarcello marlonmarcello changed the base branch from dev to release/v3.0.6 April 30, 2024 21:49
@marlonmarcello marlonmarcello changed the title Feature/accordion feature: Accordion component Apr 30, 2024
@marlonmarcello marlonmarcello added enhancement New feature or request COMP Tickets related to wethegit-components labels Apr 30, 2024
@marlonmarcello marlonmarcello linked an issue Apr 30, 2024 that may be closed by this pull request
Copy link
Contributor

Choose a reason for hiding this comment

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

Please maintain a standard and lowercase the file name.


import { Icon, IconDefs, IconSymbol, Tag, Text } from "@local/components"

import styles from "../accordion.module.scss"
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's use a single stylesheet per component.

const icon = "chevron" // Define your icon name here

const handleToggle = (index: number) => {
active === index ? setActive(null) : setActive(index)
Copy link
Contributor

Choose a reason for hiding this comment

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

Whenever using the current state to determine a new use, please use a function
https://react.dev/reference/react/useState#updating-state-based-on-the-previous-state

className?: string
}

export function Accordion({}: AccordionProps) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Doesn't look like you are using any of the props from AccordionProps, the object is empty


import styles from "./accordion.module.scss"
import AccordionItem, { CardsData } from "./component/AccordionItem"
import cards from "./content.js"
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 content should be passed to the component as a prop and not shipped with it, otherwise you can't reuse it.


<Tag
ref={contentEl}
className={`${styles.collapse} ${styles.accordionBody}`}
Copy link
Contributor

Choose a reason for hiding this comment

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

Use the classnames helper to concatenate class names

Comment on lines +80 to +87
{typeof text === "object" &&
Object.values(text).map((p, i) => (
<Text
key={i}
variant="body-smaller"
dangerouslySetInnerHTML={{ __html: p.toString() }}
/>
))}
Copy link
Contributor

@marlonmarcello marlonmarcello Apr 30, 2024

Choose a reason for hiding this comment

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

Mind explaining this a bit? Why an object instead of an array? Why the p.toString()? Seems like all you need really is an array of strings.

}
>
{typeof text === "string" && (
<Text variant="body-smaller" dangerouslySetInnerHTML={{ __html: text }} />
Copy link
Contributor

Choose a reason for hiding this comment

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

Avoid dangerouslySetInnerHTML

const contentEl = useRef<HTMLDivElement>(null)
const { title, text } = card

if (!card) return null
Copy link
Contributor

@marlonmarcello marlonmarcello Apr 30, 2024

Choose a reason for hiding this comment

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

You are de-structuring the card variable on the line above but doing the check after. Doesn't make much sense and I think the line above will throw if card is anything other than an object.

</button>
</Tag>

<Tag
Copy link
Contributor

Choose a reason for hiding this comment

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

This can be just a div no need to use Tag as it won't be replaced by a dynamic value.

@marlonmarcello marlonmarcello deleted the branch release/v3.0.6 May 22, 2024 21:03
@marlonmarcello marlonmarcello deleted the feature/accordion branch May 22, 2024 21:04
@marlonmarcello marlonmarcello restored the feature/accordion branch May 22, 2024 21:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
COMP Tickets related to wethegit-components enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[COMP] Accordion component
2 participants