Skip to content

Commit

Permalink
[DS-515] Add required examples with necessityIndicator (#561)
Browse files Browse the repository at this point in the history
  • Loading branch information
victortrinh2 authored Dec 23, 2024
2 parents 83137e9 + b3d59c9 commit 820f800
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 3 deletions.
7 changes: 6 additions & 1 deletion apps/docs/content/components/content/Label.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,15 @@ The label component has a default color, but it can be easily overridden.
<Example src="typography/Label/docs/color" />

### Required
The label component can be marked as required.
The label component can be marked as required. You can customize the necessity indicator by using an asterisk.

<Example src="typography/Label/docs/required" />

### Optional
The label component can show the optional necessity indicator as a label.

<Example src="typography/Label/docs/optional" />

<FeatureFlag flag="next">
## Advanced customization

Expand Down
3 changes: 3 additions & 0 deletions apps/docs/examples/Preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,9 @@ export const Previews: Record<string, Preview> = {
"typography/Label/docs/required": {
component: lazy(() => import("@/../../packages/components/src/typography/Label/docs/required.tsx"))
},
"typography/Label/docs/optional": {
component: lazy(() => import("@/../../packages/components/src/typography/Label/docs/optional.tsx"))
},
"typography/Label/docs/advancedCustomization": {
component: lazy(() => import("@/../../packages/components/src/typography/Label/docs/advancedCustomization.tsx"))
},
Expand Down
7 changes: 7 additions & 0 deletions packages/components/src/typography/Label/docs/optional.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Label } from "@hopper-ui/components";

export default function Example() {
return (
<Label necessityIndicator="label">Username</Label>
);
}
2 changes: 1 addition & 1 deletion packages/components/src/typography/Label/docs/required.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ import { Label } from "@hopper-ui/components";

export default function Example() {
return (
<Label isRequired>Username</Label>
<Label isRequired necessityIndicator="asterisk">Username</Label>
);
}
2 changes: 1 addition & 1 deletion packages/components/src/typography/Label/src/Label.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ function Label(props: LabelProps, ref: ForwardedRef<HTMLLabelElement>) {
{...filteredProps}
>
{children}
{(necessityIndicator === "label" && !isRequired) && <span className={styles["hop-Label__label-indicator"]}> ({necessityLabel})</span>}
{necessityIndicator === "label" && !isRequired && <span className={styles["hop-Label__label-indicator"]}> ({necessityLabel})</span>}
{necessityIndicator === "asterisk" && isRequired && requiredIndicator}
</RACLabel>
);
Expand Down

0 comments on commit 820f800

Please sign in to comment.