-
Notifications
You must be signed in to change notification settings - Fork 2
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
docs: MDS-866 Chip Component Docs #32
Changes from 10 commits
73a48b9
23ec026
d197dc4
bd8ad4d
6415057
dfbdc5f
c4aac79
b981d91
b5d4970
ff88715
e4c8511
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
Chip component is typically used to filter or trigger actions in clickable format. | ||
<br /> | ||
For example, in a UI, you might use a `<Chip />` component for: | ||
§ | ||
|
||
- Represent a selected filter category among a list | ||
- Tag associated with an item | ||
|
||
<br/> | ||
The characteristics of a `<Chip />` component are its small size, simplicity and ability to perform actions on a click |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
title: Active state | ||
--- | ||
|
||
Utilize the `isActive` prop to activate the state, set it as active by default, or maintain it in an always-active state. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
title: Customization | ||
--- | ||
|
||
You can use the `className` prop to assign any CSS classes to the `<Chip />` component. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
--- | ||
title: Default | ||
--- |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
title: Disabled status | ||
--- | ||
|
||
By passing any truthy value to the prop `disabled`, the component will prevent the click from the user. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
title: Displaying icons | ||
--- | ||
|
||
Using the props `iconRight`, `iconLeft`, `iconOnly` is possible to pass icons to the `<Chip />` component. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
title: Show stroke on hover | ||
--- | ||
|
||
Setting the `isStroke` prop to any truthy value will display the stroke on hover/active. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
title: Different sizes | ||
--- | ||
|
||
It supports two different sizes: small and medium. By default, if not specified by the prop `size`, it renders as medium. | ||
<br /> | ||
The possible values is `sm` (small) or `md` (medium). |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
title: Variants | ||
--- | ||
|
||
If the background of the element should not be visible, you can use the `"ghost"` variant by passing it through the `variant` prop to hide the default background. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
title: Adding onClick function | ||
--- | ||
|
||
Using the props `onClick` you can execute a custom function whenever the `<Chip />` component is clicked by the user, |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
"use client"; | ||
|
||
import { Chip } from "@heathmont/moon-core-tw"; | ||
import { useCallback, useState } from "react"; | ||
|
||
const sports = ["basket", "football", "cricket"]; | ||
|
||
const IsActive = () => { | ||
const [isActive, setIsActive] = useState<string[]>([]); | ||
const onClick = useCallback( | ||
(item: string) => { | ||
if (isActive.includes(item)) { | ||
setIsActive((prev: string[]) => | ||
prev.filter((sport: string) => sport !== item), | ||
); | ||
} else { | ||
setIsActive([...isActive, item]); | ||
} | ||
}, | ||
[setIsActive, isActive], | ||
); | ||
|
||
return ( | ||
<div className="flex items-center gap-2 mt-2"> | ||
<p className="text-moon-14">Hobbies (Poker is mandatory):</p> | ||
<Chip className="border border-beerus" isActive> | ||
Poker | ||
</Chip> | ||
{sports.map((item: string) => ( | ||
<Chip | ||
className="border border-beerus" | ||
karl-kallavus marked this conversation as resolved.
Show resolved
Hide resolved
|
||
onClick={() => onClick(item)} | ||
isActive={isActive.includes(item)} | ||
isStroke | ||
> | ||
{item} | ||
</Chip> | ||
))} | ||
</div> | ||
); | ||
}; | ||
|
||
export default IsActive; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
"use client"; | ||
|
||
import { Chip } from "@heathmont/moon-core-tw"; | ||
import { useCallback, useState } from "react"; | ||
|
||
const Customization = () => { | ||
const [isActive, setIsActive] = useState(false); | ||
const onClick = useCallback(() => { | ||
setIsActive(!isActive); | ||
}, [setIsActive, isActive]); | ||
|
||
return ( | ||
<> | ||
<Chip | ||
onClick={onClick} | ||
isActive={isActive} | ||
isStroke | ||
className={ | ||
isActive | ||
? "outline-none text-bulma hover:text-chichi shadow shadow-bulma hover:shadow-bulma" | ||
: "border border-beerus text-chichi hover:bg-chichi-10 hover:shadow-none" | ||
} | ||
> | ||
Custom Chip | ||
</Chip> | ||
</> | ||
); | ||
}; | ||
|
||
export default Customization; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { Chip } from "@heathmont/moon-core-tw"; | ||
|
||
const Default = () => <Chip className="border border-beerus">Default</Chip>; | ||
|
||
export default Default; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { Chip } from "@heathmont/moon-core-tw"; | ||
|
||
const Disabled = () => ( | ||
<> | ||
<Chip variant="ghost" disabled> | ||
Ghost variant | ||
</Chip> | ||
<Chip className="border border-beerus" disabled> | ||
Default variant | ||
</Chip> | ||
</> | ||
); | ||
|
||
export default Disabled; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { Chip } from "@heathmont/moon-core-tw"; | ||
import { OtherFrame } from "@heathmont/moon-icons-tw"; | ||
|
||
const sharedProps = { | ||
className: "border border-beerus", | ||
}; | ||
|
||
const Icons = () => ( | ||
<> | ||
<div className="flex flex-wrap items-center justify-start gap-2 w-full"> | ||
<p>Small:</p> | ||
<Chip | ||
{...sharedProps} | ||
size="sm" | ||
iconLeft={<OtherFrame className="text-moon-24" />} | ||
> | ||
Left Icon | ||
</Chip> | ||
<Chip | ||
{...sharedProps} | ||
size="sm" | ||
iconRight={<OtherFrame className="text-moon-24" />} | ||
> | ||
Right Icon | ||
</Chip> | ||
<Chip | ||
{...sharedProps} | ||
size="sm" | ||
iconRight={<OtherFrame className="text-moon-24" />} | ||
iconLeft={<OtherFrame className="text-moon-24" />} | ||
> | ||
Left/Right Icons | ||
</Chip> | ||
<Chip | ||
{...sharedProps} | ||
size="sm" | ||
iconOnly={<OtherFrame className="text-moon-24" />} | ||
aria-label="Single icon" | ||
/> | ||
</div> | ||
<div className="flex flex-wrap items-center justify-start gap-2 w-full"> | ||
<p>Medium:</p> | ||
<Chip {...sharedProps} iconLeft={<OtherFrame className="text-moon-24" />}> | ||
Left Icon | ||
</Chip> | ||
<Chip | ||
{...sharedProps} | ||
iconRight={<OtherFrame className="text-moon-24" />} | ||
> | ||
Right Icon | ||
</Chip> | ||
<Chip | ||
{...sharedProps} | ||
iconRight={<OtherFrame className="text-moon-24" />} | ||
iconLeft={<OtherFrame className="text-moon-24" />} | ||
> | ||
Left/Right Icons | ||
</Chip> | ||
<Chip | ||
{...sharedProps} | ||
iconOnly={<OtherFrame className="text-moon-24" />} | ||
aria-label="Single icon" | ||
/> | ||
</div> | ||
</> | ||
); | ||
|
||
export default Icons; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { Chip } from "@heathmont/moon-core-tw"; | ||
import { OtherFrame } from "@heathmont/moon-icons-tw"; | ||
|
||
const StrokeOnHover = () => ( | ||
<> | ||
<Chip className="border border-beerus" isStroke> | ||
Hover me | ||
</Chip> | ||
<Chip | ||
iconRight={<OtherFrame className="text-moon-24" />} | ||
isStroke | ||
className="border border-beerus" | ||
> | ||
Right Icon | ||
</Chip> | ||
<Chip | ||
className="border border-beerus" | ||
iconLeft={<OtherFrame className="text-moon-24" />} | ||
isStroke | ||
> | ||
Left Icon | ||
</Chip> | ||
</> | ||
); | ||
|
||
export default StrokeOnHover; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { Chip } from "@heathmont/moon-core-tw"; | ||
|
||
const Sizes = () => ( | ||
<> | ||
<Chip className="border border-beerus" size="sm"> | ||
Small | ||
</Chip> | ||
<Chip className="border border-beerus">Medium is Default</Chip> | ||
</> | ||
); | ||
|
||
export default Sizes; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { Chip } from "@heathmont/moon-core-tw"; | ||
|
||
const Variants = () => ( | ||
<> | ||
<Chip variant="ghost">Ghost variant</Chip> | ||
<Chip className="border border-beerus">Default variant</Chip> | ||
</> | ||
); | ||
|
||
export default Variants; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
"use client"; | ||
|
||
import { Chip } from "@heathmont/moon-core-tw"; | ||
|
||
const WithOnClick = () => { | ||
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. The previous example was printing a console.log statement, which lacked visual appeal. The question is Chip component is suitable for acting as a button? Any insights on this matter would be appreciated 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. @salvatorecriscioneweb, this is a good question. We definitely need to describe the difference between a chip and a button. @dkireev, could you please assist with a good description in a separate PR? Regarding acting as a button, let's leave it for now as it is 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. Basically, the main difference is that a chip supports an 'Active' state, indicating that the appropriate field was selected. However, we need to add a concrete and straightforward description. 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. Yeah, added the alert for now to enable end-to-end testing on the click, as using console.log isn't very effective for tracking in Playwright |
||
return ( | ||
<Chip | ||
className="border border-beerus" | ||
onClick={() => alert("Chip clicked")} | ||
> | ||
Click me | ||
</Chip> | ||
); | ||
}; | ||
|
||
export default WithOnClick; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import React from "react"; | ||
import dynamic from "next/dynamic"; | ||
import { Loader } from "@heathmont/moon-base-tw"; | ||
import { getExamples } from "@/utils/getExamples"; | ||
import { ExampleSectionData } from "@/components/exampleSection/ExampleSection"; | ||
import { MainLayout } from "@/components/MainLayout"; | ||
import { PageHeadComponent } from "@/components/PageHeadComponent"; | ||
import { PropsTable } from "@/components/propsTable"; | ||
|
||
import props from "./props"; | ||
import image from "./chip.webp"; | ||
|
||
const ordered = [ | ||
"Default", | ||
"Sizes", | ||
"Variants", | ||
"Active", | ||
"Disabled", | ||
"Icons", | ||
"IsStroke", | ||
"WithOnClick", | ||
"Customization", | ||
]; | ||
|
||
export default async function AuthCodePage(request: { | ||
searchParams: { raw: string }; | ||
}) { | ||
const { | ||
client: { | ||
chip: { description, descriptions: exampleDescriptions, examples }, | ||
}, | ||
} = await getExamples(); | ||
|
||
const searchParam = request?.searchParams?.raw; | ||
const isMockup = !!searchParam && Object.keys(examples).includes(searchParam); | ||
|
||
if (isMockup) { | ||
const Component = dynamic( | ||
() => import(`@/app/client/chip/examples/${searchParam}`), | ||
{ | ||
loading: () => <Loader />, | ||
ssr: false, | ||
}, | ||
); | ||
return ( | ||
<div className="p-4" id="playwright-test"> | ||
<Component /> | ||
</div> | ||
); | ||
} | ||
|
||
return ( | ||
<MainLayout | ||
isMockup={isMockup} | ||
componentName="chip" | ||
contentSidebar={ordered} | ||
> | ||
<div className="flex flex-col gap-12 text-moon-14 pb-20"> | ||
<PageHeadComponent | ||
title={"Chip"} | ||
description={description} | ||
tags={["ARIA", "RTL"]} | ||
image={image} | ||
/> | ||
|
||
<ExampleSectionData | ||
componentName="chip" | ||
client={{ | ||
description, | ||
descriptions: exampleDescriptions, | ||
examples, | ||
}} | ||
data={ordered} | ||
/> | ||
<PropsTable | ||
title="Chip props" | ||
description={ | ||
<p> | ||
These are props specific to the{" "} | ||
<span className="text-frieza">Chip</span> component: | ||
</p> | ||
} | ||
data={props} | ||
/> | ||
</div> | ||
</MainLayout> | ||
); | ||
} |
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.
@karl-kallavus also this example was rewrote and created brand new for better clarification. Let me know if it's ok