-
Notifications
You must be signed in to change notification settings - Fork 3.6k
[WEB-4733] dev: propel toolbar component #7742
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
d1d1669
dev: toolbar component added to propel
anmolsinghbhatia 2e6d030
dev: toolbar story added
anmolsinghbhatia 5fccc18
chore: propel config updated
anmolsinghbhatia 469b949
chore: code refactor
anmolsinghbhatia 6088e67
fix: merge conflicts from preview
sriramveeraghanta File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| export { Toolbar } from "./toolbar"; | ||
| export type { | ||
| ToolbarProps, | ||
| ToolbarGroupProps, | ||
| ToolbarItemProps, | ||
| ToolbarSeparatorProps, | ||
| ToolbarSubmitButtonProps, | ||
| } from "./toolbar"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,123 @@ | ||
| import type { Meta, StoryObj } from "@storybook/react-vite"; | ||
| import { | ||
| Bold, | ||
| Italic, | ||
| Underline, | ||
| Strikethrough, | ||
| Code, | ||
| Link, | ||
| List, | ||
| ListOrdered, | ||
| Quote, | ||
| AlignLeft, | ||
| AlignCenter, | ||
| AlignRight, | ||
| Undo, | ||
| Redo, | ||
| Globe2, | ||
| Lock, | ||
| } from "lucide-react"; | ||
| import { Toolbar } from "./toolbar"; | ||
|
|
||
| const meta: Meta<typeof Toolbar> = { | ||
| title: "Components/Toolbar", | ||
| component: Toolbar, | ||
| parameters: { | ||
| layout: "fullscreen", | ||
| }, | ||
| tags: ["autodocs"], | ||
| }; | ||
|
|
||
| export default meta; | ||
| type Story = StoryObj<typeof Toolbar>; | ||
|
|
||
| export const Default: Story = { | ||
| render: () => ( | ||
| <div className="p-4 space-y-4"> | ||
| <div className="w-96 border rounded"> | ||
| <Toolbar> | ||
| <Toolbar.Group isFirst> | ||
| <Toolbar.Item icon={Undo} tooltip="Undo" /> | ||
| <Toolbar.Item icon={Redo} tooltip="Redo" /> | ||
| </Toolbar.Group> | ||
| <Toolbar.Group> | ||
| <Toolbar.Item icon={Bold} tooltip="Bold" /> | ||
| <Toolbar.Item icon={Italic} tooltip="Italic" /> | ||
| <Toolbar.Item icon={Underline} tooltip="Underline" /> | ||
| <Toolbar.Item icon={Strikethrough} tooltip="Strikethrough" /> | ||
| </Toolbar.Group> | ||
| <Toolbar.Group> | ||
| <Toolbar.Item icon={List} tooltip="Bullet List" /> | ||
| <Toolbar.Item icon={ListOrdered} tooltip="Numbered List" /> | ||
| <Toolbar.Item icon={Quote} tooltip="Quote" /> | ||
| </Toolbar.Group> | ||
| <Toolbar.Group> | ||
| <Toolbar.Item icon={AlignLeft} tooltip="Align Left" /> | ||
| <Toolbar.Item icon={AlignCenter} tooltip="Align Center" /> | ||
| <Toolbar.Item icon={AlignRight} tooltip="Align Right" /> | ||
| </Toolbar.Group> | ||
| <Toolbar.Group> | ||
| <Toolbar.Item icon={Link} tooltip="Link" /> | ||
| <Toolbar.Item icon={Code} tooltip="Code" /> | ||
| </Toolbar.Group> | ||
| </Toolbar> | ||
| </div> | ||
| </div> | ||
| ), | ||
| }; | ||
|
|
||
| export const WithActiveStates: Story = { | ||
| render: () => ( | ||
| <div className="p-4"> | ||
| <Toolbar> | ||
| <Toolbar.Group isFirst> | ||
| <Toolbar.Item icon={Bold} tooltip="Bold" shortcut={["Cmd", "B"]} isActive /> | ||
| <Toolbar.Item icon={Italic} tooltip="Italic" shortcut={["Cmd", "I"]} /> | ||
| <Toolbar.Item icon={Underline} tooltip="Underline" shortcut={["Cmd", "U"]} isActive /> | ||
| </Toolbar.Group> | ||
| <Toolbar.Group> | ||
| <Toolbar.Item icon={List} tooltip="Bullet List" /> | ||
| <Toolbar.Item icon={ListOrdered} tooltip="Numbered List" isActive /> | ||
| <Toolbar.Item icon={Quote} tooltip="Quote" /> | ||
| </Toolbar.Group> | ||
| <Toolbar.Group> | ||
| <Toolbar.Item icon={AlignLeft} tooltip="Align Left" /> | ||
| <Toolbar.Item icon={AlignCenter} tooltip="Align Center" isActive /> | ||
| <Toolbar.Item icon={AlignRight} tooltip="Align Right" /> | ||
| </Toolbar.Group> | ||
| </Toolbar> | ||
| </div> | ||
| ), | ||
| }; | ||
|
|
||
| export const CommentToolbar: Story = { | ||
| render: () => ( | ||
| <div className="p-4 space-y-4"> | ||
| <h3 className="text-sm font-medium">Comment Toolbar with Access Control</h3> | ||
| <div className="rounded border-[0.5px] border-custom-border-200 p-1"> | ||
| <Toolbar> | ||
| {/* Access Specifier */} | ||
| <div className="flex flex-shrink-0 items-stretch gap-0.5 rounded border-[0.5px] border-custom-border-200 p-1"> | ||
| <Toolbar.Item icon={Lock} tooltip="Private" isActive /> | ||
| <Toolbar.Item icon={Globe2} tooltip="Public" /> | ||
| </div> | ||
|
|
||
| <div className="flex w-full items-stretch justify-between gap-2 rounded border-[0.5px] border-custom-border-200 p-1"> | ||
| <div className="flex items-stretch"> | ||
| <Toolbar.Group isFirst> | ||
| <Toolbar.Item icon={Bold} tooltip="Bold" shortcut={["Cmd", "B"]} /> | ||
| <Toolbar.Item icon={Italic} tooltip="Italic" shortcut={["Cmd", "I"]} /> | ||
| <Toolbar.Item icon={Code} tooltip="Code" shortcut={["Cmd", "`"]} /> | ||
| </Toolbar.Group> | ||
| <Toolbar.Group> | ||
| <Toolbar.Item icon={List} tooltip="Bullet List" /> | ||
| <Toolbar.Item icon={ListOrdered} tooltip="Numbered List" /> | ||
| </Toolbar.Group> | ||
| </div> | ||
| <Toolbar.SubmitButton>Comment</Toolbar.SubmitButton> | ||
| </div> | ||
| </Toolbar> | ||
| </div> | ||
| </div> | ||
| ), | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,159 @@ | ||
| import * as React from "react"; | ||
| import { LucideIcon } from "lucide-react"; | ||
| import { Tooltip } from "../tooltip"; | ||
| import { cn } from "../utils"; | ||
|
|
||
| export interface ToolbarProps extends React.HTMLAttributes<HTMLDivElement> { | ||
| children: React.ReactNode; | ||
| className?: string; | ||
| } | ||
|
|
||
| export interface ToolbarGroupProps extends React.HTMLAttributes<HTMLDivElement> { | ||
| children: React.ReactNode; | ||
| className?: string; | ||
| isFirst?: boolean; | ||
| } | ||
|
|
||
| export interface ToolbarItemProps extends React.ButtonHTMLAttributes<HTMLButtonElement> { | ||
| icon: LucideIcon; | ||
| isActive?: boolean; | ||
| tooltip?: string; | ||
| shortcut?: string[]; | ||
| className?: string; | ||
| children?: React.ReactNode; | ||
| } | ||
|
|
||
| export interface ToolbarSeparatorProps extends React.HTMLAttributes<HTMLDivElement> { | ||
| className?: string; | ||
| } | ||
|
|
||
| export interface ToolbarSubmitButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> { | ||
| loading?: boolean; | ||
| variant?: "primary" | "secondary" | "outline" | "ghost" | "destructive"; | ||
| className?: string; | ||
| children: React.ReactNode; | ||
| } | ||
|
|
||
| const ToolbarRoot = React.forwardRef<HTMLDivElement, ToolbarProps>(({ className, children, ...props }, ref) => ( | ||
| <div | ||
| ref={ref} | ||
| className={cn("flex h-9 w-full items-stretch gap-1.5 bg-custom-background-90 overflow-x-scroll", className)} | ||
| {...props} | ||
| > | ||
| {children} | ||
| </div> | ||
| )); | ||
|
|
||
anmolsinghbhatia marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| const ToolbarGroup = React.forwardRef<HTMLDivElement, ToolbarGroupProps>( | ||
| ({ className, children, isFirst = false, ...props }, ref) => ( | ||
| <div | ||
| ref={ref} | ||
| className={cn( | ||
| "flex items-stretch gap-0.5 border-r border-custom-border-200 px-2.5", | ||
| { | ||
| "pl-0": isFirst, | ||
| }, | ||
| className | ||
| )} | ||
| {...props} | ||
| > | ||
| {children} | ||
| </div> | ||
| ) | ||
| ); | ||
|
|
||
| const ToolbarItem = React.forwardRef<HTMLButtonElement, ToolbarItemProps>( | ||
| ({ icon: Icon, isActive = false, tooltip, shortcut, className, children, ...props }, ref) => { | ||
| const button = ( | ||
| <button | ||
| ref={ref} | ||
| type="button" | ||
| className={cn( | ||
| "grid place-items-center aspect-square rounded-sm p-0.5 text-custom-text-400 hover:bg-custom-background-80 transition-colors", | ||
| { | ||
| "bg-custom-background-80 text-custom-text-100": isActive, | ||
| }, | ||
| className | ||
| )} | ||
| {...props} | ||
| > | ||
| <Icon | ||
| className={cn("h-3.5 w-3.5", { | ||
| "text-custom-text-100": isActive, | ||
| })} | ||
| strokeWidth={2.5} | ||
| /> | ||
| {children} | ||
| </button> | ||
| ); | ||
anmolsinghbhatia marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| if (tooltip) { | ||
| return ( | ||
| <Tooltip | ||
| tooltipContent={ | ||
| <div className="flex flex-col gap-1 text-center text-xs"> | ||
| <span className="font-medium">{tooltip}</span> | ||
| {shortcut && <kbd className="text-custom-text-400">{shortcut.join(" + ")}</kbd>} | ||
| </div> | ||
| } | ||
| > | ||
| {button} | ||
| </Tooltip> | ||
| ); | ||
| } | ||
|
|
||
| return button; | ||
| } | ||
| ); | ||
|
|
||
| const ToolbarSeparator = React.forwardRef<HTMLDivElement, ToolbarSeparatorProps>(({ className, ...props }, ref) => ( | ||
| <div ref={ref} className={cn("h-full w-px bg-custom-border-200 mx-1", className)} {...props} /> | ||
| )); | ||
|
|
||
| const buttonVariants = { | ||
| primary: "bg-custom-primary-100 text-white hover:bg-custom-primary-200 focus:bg-custom-primary-200", | ||
| secondary: | ||
| "bg-custom-background-100 text-custom-text-200 border border-custom-border-200 hover:bg-custom-background-90 focus:bg-custom-background-90", | ||
| outline: | ||
| "border border-custom-primary-100 text-custom-primary-100 bg-transparent hover:bg-custom-primary-100/10 focus:bg-custom-primary-100/20", | ||
| ghost: "text-custom-text-200 hover:bg-custom-background-90 focus:bg-custom-background-90", | ||
| destructive: "bg-red-500 text-white hover:bg-red-600 focus:bg-red-600", | ||
| }; | ||
|
|
||
| const ToolbarSubmitButton = React.forwardRef<HTMLButtonElement, ToolbarSubmitButtonProps>( | ||
| ({ loading = false, variant = "primary", className, children, disabled, ...props }, ref) => ( | ||
| <div className="sticky right-1"> | ||
anmolsinghbhatia marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| <button | ||
| ref={ref} | ||
| className={cn( | ||
| "inline-flex items-center justify-center gap-2 rounded-md px-2.5 py-1.5 text-xs font-medium transition-colors duration-200", | ||
| "focus:outline-none focus:ring-2 focus:ring-custom-primary-100/20 focus:ring-offset-2", | ||
| "disabled:opacity-50 disabled:pointer-events-none", | ||
| buttonVariants[variant], | ||
| className | ||
| )} | ||
| disabled={disabled || loading} | ||
| {...props} | ||
| > | ||
| {loading && <div className="h-3 w-3 animate-spin rounded-full border border-current border-t-transparent" />} | ||
| {children} | ||
| </button> | ||
| </div> | ||
| ) | ||
| ); | ||
|
|
||
| ToolbarRoot.displayName = "ToolbarRoot"; | ||
| ToolbarGroup.displayName = "ToolbarGroup"; | ||
| ToolbarItem.displayName = "ToolbarItem"; | ||
| ToolbarSeparator.displayName = "ToolbarSeparator"; | ||
| ToolbarSubmitButton.displayName = "ToolbarSubmitButton"; | ||
|
|
||
| // compound components | ||
| const Toolbar = Object.assign(ToolbarRoot, { | ||
| Group: ToolbarGroup, | ||
| Item: ToolbarItem, | ||
| Separator: ToolbarSeparator, | ||
| SubmitButton: ToolbarSubmitButton, | ||
| }); | ||
|
|
||
| export { Toolbar }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.