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

♻️ Refacto chips #244

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 9 additions & 34 deletions packages/react/components/chips/Chips.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React from "react"
import { is } from "@/services"
import { ChipsProps } from "./ChipsProps"
import clsx from "clsx"
import { hashClass } from "@/helpers"
import { useTrilogyContext } from "@/context"
import React from 'react'
import { is } from '@/services'
import { ChipsProps } from './ChipsProps'
import clsx from 'clsx'
import { hashClass } from '@/helpers'
import { useTrilogyContext } from '@/context'

/**
* Chips Component - has to be in a ChipsList component
Expand All @@ -17,38 +17,13 @@ import { useTrilogyContext } from "@/context"
* @param testId {string} Test Id for Test Integration
* @param others
*/
const Chips = ({
className,
onClick,
children,
active,
disabled,
id,
...others
}: ChipsProps): JSX.Element => {
const Chips = ({ className, children, active = false, disabled, id, ...others }: ChipsProps): JSX.Element => {
const { styled } = useTrilogyContext()

const classes = hashClass(
styled,
clsx(
"chips",
active && is("active"),
className
)
)
const classes = hashClass(styled, clsx('chips', active && is('active'), className))

return (
<button
{...{ disabled: disabled }}
aria-disabled={disabled}
id={id}
aria-pressed={!!active}
className={classes}
onClick={(e) => {
onClick?.(e)
}}
{...others}
>
<button disabled={disabled} aria-disabled={disabled} id={id} aria-pressed={active} className={classes} {...others}>
{children}
</button>
)
Expand Down
2 changes: 1 addition & 1 deletion packages/react/components/chips/ChipsProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { CommonProps } from '../../objects/facets/CommonProps'
* Chips Interface
*/
export interface ChipsProps extends Clickable, Accessibility, Dev, CommonProps {
children: string | React.ReactNode
children: React.ReactNode
onClick?: ClickEvent
active?: boolean
disabled?: boolean
Expand Down
2 changes: 1 addition & 1 deletion packages/react/components/chips/list/ChipsListProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { CommonProps } from '../../../objects/facets/CommonProps'

export interface ChipsListProps extends CommonProps {
children?: React.ReactNode | React.ReactElement
children?: React.ReactNode
multiple?: boolean
scrollable?: boolean
}