-
-
Notifications
You must be signed in to change notification settings - Fork 31
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
Part 2: fixed linter issues #342
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
#!/bin/sh | ||
#!/usr/bin/env sh | ||
. "$(dirname -- "$0")/_/husky.sh" | ||
|
||
echo "Linting your changes..." | ||
npx pretty-quick --staged | ||
npm run lint | ||
#! npm run lint | ||
|
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,42 @@ | ||
import React, {useState} from 'react'; | ||
import AccordionRoot from './shards/AccordionRoot'; | ||
import AccordionItem from './shards/AccordionItem'; | ||
import AccordionHeader from './shards/AccordionHeader'; | ||
import AccordionTrigger from './shards/AccordionTrigger'; | ||
import AccordionContent from './shards/AccordionContent'; | ||
import React, { useState } from 'react' | ||
import AccordionRoot from './shards/AccordionRoot' | ||
import AccordionItem from './shards/AccordionItem' | ||
import AccordionHeader from './shards/AccordionHeader' | ||
import AccordionTrigger from './shards/AccordionTrigger' | ||
import AccordionContent from './shards/AccordionContent' | ||
|
||
export type AccordionProps = { | ||
items: {content: any}[]; | ||
items: { content: any }[] | ||
} | ||
|
||
const Accordion = ({items} : AccordionProps) => { | ||
const [activeIndex, setActiveIndex] = useState<number>(-1); | ||
const handleClick = (index: number) => { | ||
setActiveIndex(activeIndex === index ? -1 : index); | ||
}; | ||
const Accordion = ({ items }: AccordionProps) => { | ||
const [activeIndex, setActiveIndex] = useState<number>(-1) | ||
const handleClick = (index: number) => { | ||
setActiveIndex(activeIndex === index ? -1 : index) | ||
} | ||
|
||
return ( | ||
<AccordionRoot> | ||
{items.map((item, index) => ( | ||
<AccordionItem value={index}> | ||
<AccordionHeader> | ||
<AccordionTrigger handleClick={handleClick} index={index} activeIndex={activeIndex} > | ||
Item {index+1} | ||
</AccordionTrigger> | ||
</AccordionHeader> | ||
<AccordionContent index={index} activeIndex={activeIndex}> | ||
{item.content} | ||
</AccordionContent> | ||
</AccordionItem> | ||
))} | ||
</AccordionRoot> | ||
); | ||
}; | ||
return ( | ||
<AccordionRoot> | ||
{items.map((item, index) => ( | ||
<AccordionItem value={index}> | ||
<AccordionHeader> | ||
<AccordionTrigger | ||
handleClick={handleClick} | ||
index={index} | ||
activeIndex={activeIndex} | ||
> | ||
Item {index + 1} | ||
</AccordionTrigger> | ||
</AccordionHeader> | ||
<AccordionContent index={index} activeIndex={activeIndex}> | ||
{item.content} | ||
</AccordionContent> | ||
</AccordionItem> | ||
))} | ||
</AccordionRoot> | ||
) | ||
} | ||
|
||
Accordion.Root = AccordionRoot; | ||
Accordion.Root = AccordionRoot | ||
|
||
export default Accordion; | ||
export default Accordion |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,32 @@ | ||
import React from 'react'; | ||
// @ts-ignore | ||
import {customClassSwitcher} from '~/core'; | ||
import React from 'react' | ||
import { customClassSwitcher } from '~/core' | ||
|
||
type AccordionContentProps = { | ||
children: React.ReactNode; | ||
index: number, | ||
activeIndex: number, | ||
customRootClass? :string | ||
}; | ||
children: React.ReactNode | ||
index: number | ||
activeIndex: number | ||
customRootClass?: string | ||
} | ||
|
||
const AccordionContent: React.FC<AccordionContentProps> = ({children, index, activeIndex, customRootClass}: AccordionContentProps) => { | ||
const rootClass = customClassSwitcher(customRootClass, 'Accordion'); | ||
return ( | ||
<span className={`${rootClass}-content`}> | ||
<div | ||
id={`content-${index}`} | ||
role="region" | ||
aria-labelledby={`section-${index}`} | ||
hidden={activeIndex !== index} | ||
> | ||
{children} | ||
</div> | ||
</span> | ||
); | ||
}; | ||
const AccordionContent: React.FC<AccordionContentProps> = ({ | ||
children, | ||
index, | ||
activeIndex, | ||
customRootClass | ||
}: AccordionContentProps) => { | ||
const rootClass = customClassSwitcher(customRootClass, 'Accordion') | ||
return ( | ||
<span className={`${rootClass}-content`}> | ||
<div | ||
id={`content-${index}`} | ||
role="region" | ||
aria-labelledby={`section-${index}`} | ||
hidden={activeIndex !== index} | ||
> | ||
{children} | ||
</div> | ||
</span> | ||
) | ||
} | ||
|
||
export default AccordionContent; | ||
export default AccordionContent |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,17 @@ | ||
import React from 'react'; | ||
// @ts-ignore | ||
import {customClassSwitcher} from '~/core'; | ||
import React from 'react' | ||
import { customClassSwitcher } from '~/core' | ||
|
||
export type AccordionHeaderProps = { | ||
children: React.ReactNode; | ||
customHeaderClass?: string; | ||
children: React.ReactNode | ||
customHeaderClass?: string | ||
} | ||
|
||
const AccordionHeader: React.FC<AccordionHeaderProps> = ({children, customHeaderClass=''}) => { | ||
const rootClass = customClassSwitcher(customHeaderClass, 'Accordion'); | ||
return ( | ||
<div className={`${rootClass}-header`}> | ||
{children} | ||
</div> | ||
); | ||
}; | ||
const AccordionHeader: React.FC<AccordionHeaderProps> = ({ | ||
children, | ||
customHeaderClass = '' | ||
}) => { | ||
const rootClass = customClassSwitcher(customHeaderClass, 'Accordion') | ||
return <div className={`${rootClass}-header`}>{children}</div> | ||
} | ||
|
||
export default AccordionHeader; | ||
export default AccordionHeader |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,18 @@ | ||
import React from 'react'; | ||
// @ts-ignore | ||
import {customClassSwitcher} from '~/core'; | ||
import React from 'react' | ||
import { customClassSwitcher } from '~/core' | ||
|
||
export type AccordionItemProps = { | ||
children: React.ReactNode; | ||
customItemClass?: string; | ||
value?: number; | ||
children: React.ReactNode | ||
customItemClass?: string | ||
value?: number | ||
} | ||
|
||
const AccordionItem: React.FC<AccordionItemProps> = ({children, value, customItemClass=''}) => { | ||
const rootClass = customClassSwitcher(customItemClass, 'Accordion'); | ||
return ( | ||
<div className={`${rootClass}-item`}> | ||
{children} | ||
</div> | ||
); | ||
}; | ||
const AccordionItem: React.FC<AccordionItemProps> = ({ | ||
children, | ||
customItemClass = '' | ||
}) => { | ||
const rootClass = customClassSwitcher(customItemClass, 'Accordion') | ||
return <div className={`${rootClass}-item`}>{children}</div> | ||
} | ||
|
||
export default AccordionItem; | ||
export default AccordionItem |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,14 @@ | ||
import React from 'react'; | ||
// @ts-ignore | ||
import {customClassSwitcher} from '~/core'; | ||
import React from 'react' | ||
import { customClassSwitcher } from '~/core' | ||
|
||
export type AccordionRootProps = { | ||
children: React.ReactNode; | ||
customRootClass?: string; | ||
children: React.ReactNode | ||
customRootClass?: string | ||
} | ||
|
||
const AccordionRoot= ({children, customRootClass}: AccordionRootProps) => { | ||
const rootClass = customClassSwitcher(customRootClass, 'Accordion'); | ||
return ( | ||
<span className={`${rootClass}-root`}> | ||
{children} | ||
</span> | ||
); | ||
}; | ||
const AccordionRoot = ({ children, customRootClass }: AccordionRootProps) => { | ||
const rootClass = customClassSwitcher(customRootClass, 'Accordion') | ||
return <span className={`${rootClass}-root`}>{children}</span> | ||
} | ||
|
||
export default AccordionRoot; | ||
export default AccordionRoot |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,30 +1,33 @@ | ||||||||||||||||||||||||
import React from 'react'; | ||||||||||||||||||||||||
// @ts-ignore | ||||||||||||||||||||||||
import {customClassSwitcher} from '~/core'; | ||||||||||||||||||||||||
import React from 'react' | ||||||||||||||||||||||||
import { customClassSwitcher } from '~/core' | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
type AccordionTriggerProps = { | ||||||||||||||||||||||||
children: React.ReactNode; | ||||||||||||||||||||||||
customRootClass?: string, | ||||||||||||||||||||||||
index: number, | ||||||||||||||||||||||||
activeIndex: number, | ||||||||||||||||||||||||
children: React.ReactNode | ||||||||||||||||||||||||
customRootClass?: string | ||||||||||||||||||||||||
index: number | ||||||||||||||||||||||||
activeIndex: number | ||||||||||||||||||||||||
handleClick: (index: number) => void | ||||||||||||||||||||||||
}; | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
const AccordionTrigger: React.FC<AccordionTriggerProps> = ({children, handleClick, index, activeIndex, customRootClass}) => { | ||||||||||||||||||||||||
const rootClass = customClassSwitcher(customRootClass, 'Accordion'); | ||||||||||||||||||||||||
return ( | ||||||||||||||||||||||||
<span className={`${rootClass}-trigger`}> | ||||||||||||||||||||||||
const AccordionTrigger: React.FC<AccordionTriggerProps> = ({ | ||||||||||||||||||||||||
children, | ||||||||||||||||||||||||
handleClick, | ||||||||||||||||||||||||
index, | ||||||||||||||||||||||||
activeIndex, | ||||||||||||||||||||||||
customRootClass | ||||||||||||||||||||||||
}) => { | ||||||||||||||||||||||||
const rootClass = customClassSwitcher(customRootClass, 'Accordion') | ||||||||||||||||||||||||
return ( | ||||||||||||||||||||||||
<span className={`${rootClass}-trigger`}> | ||||||||||||||||||||||||
<button | ||||||||||||||||||||||||
onClick={() => handleClick(index)} | ||||||||||||||||||||||||
aria-expanded={activeIndex === index} | ||||||||||||||||||||||||
aria-controls={`content-${index}`} | ||||||||||||||||||||||||
> | ||||||||||||||||||||||||
{children} | ||||||||||||||||||||||||
Comment on lines
+22
to
+26
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add explicit button type to prevent form submission issues. The button within the accordion trigger should explicitly specify its type to avoid unintentional form submissions when used within a form. - <button
+ <button type="button" Committable suggestion
Suggested change
ToolsBiome
|
||||||||||||||||||||||||
</button> | ||||||||||||||||||||||||
</span> | ||||||||||||||||||||||||
) | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
<button | ||||||||||||||||||||||||
onClick={() => handleClick(index)} | ||||||||||||||||||||||||
aria-expanded={activeIndex === index} | ||||||||||||||||||||||||
aria-controls={`content-${index}`} | ||||||||||||||||||||||||
> | ||||||||||||||||||||||||
{children} | ||||||||||||||||||||||||
</button> | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
</span> | ||||||||||||||||||||||||
); | ||||||||||||||||||||||||
}; | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
export default AccordionTrigger; | ||||||||||||||||||||||||
export default AccordionTrigger |
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.
Add a key property to the list items.
The React documentation and best practices recommend using a unique key for list items to help React track each component's identity during updates. This is missing in the map function for
AccordionItem
.Committable suggestion
Tools
Biome