Skip to content

Commit 0f53730

Browse files
committed
feat(text-ellipsis): add new component & add support to badge
1 parent fdcd124 commit 0f53730

File tree

12 files changed

+1010
-75
lines changed

12 files changed

+1010
-75
lines changed

apps/docs/stories/badge.stories.tsx

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,111 @@ export const CapitalizedText: Story = {
529529
),
530530
};
531531

532+
export const TextEllipsisPositions: Story = {
533+
parameters: {
534+
docs: {
535+
description: {
536+
story:
537+
'The `textEllipsis` prop enables canvas-based text truncation with ellipsis at different positions. Use `true` or `"center"` for center truncation (default), `"start"` for start truncation, or `"end"` for end truncation. Only works with string children.',
538+
},
539+
},
540+
},
541+
argTypes: {
542+
children: { control: false },
543+
color: { control: false },
544+
variant: { control: false },
545+
capitalize: { control: false },
546+
asChild: { control: false },
547+
textEllipsis: { control: false },
548+
},
549+
render: () => (
550+
<div className="space-y-6">
551+
<div>
552+
<h3 className="text-sm font-medium mb-2 text-vanilla-800 dark:text-vanilla-300">
553+
Ellipsis Positions
554+
</h3>
555+
<div className="flex flex-col gap-3">
556+
<div className="flex items-center gap-3">
557+
<span className="text-xs text-vanilla-600 dark:text-vanilla-300 w-16">Center:</span>
558+
<div style={{ '--badge-width': '180px' } as React.CSSProperties}>
559+
<Badge color="robin" textEllipsis="center">
560+
This is a very long badge text that will be truncated in the center
561+
</Badge>
562+
</div>
563+
</div>
564+
<div className="flex items-center gap-3">
565+
<span className="text-xs text-vanilla-600 dark:text-vanilla-300 w-16">Start:</span>
566+
<div style={{ '--badge-width': '180px' } as React.CSSProperties}>
567+
<Badge color="forest" textEllipsis="start">
568+
path/to/very/long/filename/that/needs/truncation.tsx
569+
</Badge>
570+
</div>
571+
</div>
572+
<div className="flex items-center gap-3">
573+
<span className="text-xs text-vanilla-600 dark:text-vanilla-300 w-16">End:</span>
574+
<div style={{ '--badge-width': '180px' } as React.CSSProperties}>
575+
<Badge color="amber" textEllipsis="end">
576+
A long description that should be truncated at the end
577+
</Badge>
578+
</div>
579+
</div>
580+
</div>
581+
</div>
582+
<div>
583+
<h3 className="text-sm font-medium mb-2 text-vanilla-800 dark:text-vanilla-300">
584+
Boolean Shorthand (defaults to center)
585+
</h3>
586+
<div className="flex flex-col gap-2">
587+
<div style={{ '--badge-width': '200px' } as React.CSSProperties}>
588+
<Badge color="aqua" textEllipsis>
589+
Using textEllipsis=true defaults to center truncation
590+
</Badge>
591+
</div>
592+
</div>
593+
</div>
594+
<div>
595+
<h3 className="text-sm font-medium mb-2 text-vanilla-800 dark:text-vanilla-300">
596+
With Outline Variant
597+
</h3>
598+
<div className="flex flex-col gap-2">
599+
<div style={{ '--badge-width': '160px' } as React.CSSProperties}>
600+
<Badge color="cherry" variant="outline" textEllipsis="center">
601+
Error: Connection timeout after 30 seconds of inactivity
602+
</Badge>
603+
</div>
604+
<div style={{ '--badge-width': '160px' } as React.CSSProperties}>
605+
<Badge color="sakura" variant="outline" textEllipsis="end">
606+
User: very.long.email.address@example.domain.com
607+
</Badge>
608+
</div>
609+
</div>
610+
</div>
611+
<div>
612+
<h3 className="text-sm font-medium mb-2 text-vanilla-800 dark:text-vanilla-300">
613+
Container Constrained
614+
</h3>
615+
<p className="text-xs text-vanilla-600 dark:text-vanilla-300 mb-2">
616+
Badges inside a narrow container will truncate automatically with textEllipsis
617+
</p>
618+
<div
619+
className="flex flex-col gap-2 p-2 border border-vanilla-300 dark:border-vanilla-700 rounded"
620+
style={{ width: '220px', '--badge-width': '100%' } as React.CSSProperties}
621+
>
622+
<Badge color="robin" textEllipsis="center">
623+
kubernetes-deployment-production-east-us-2
624+
</Badge>
625+
<Badge color="forest" variant="outline" textEllipsis="start">
626+
/var/log/application/server/debug/2024-01-15.log
627+
</Badge>
628+
<Badge color="sienna" textEllipsis="end">
629+
Successfully processed 1,234 items in batch
630+
</Badge>
631+
</div>
632+
</div>
633+
</div>
634+
),
635+
};
636+
532637
export const UsingAsChild: Story = {
533638
parameters: {
534639
docs: {

0 commit comments

Comments
 (0)