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

feat(Toggle group): Add support for icon position #10291

Merged
merged 5 commits into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ export interface ToggleGroupItemProps extends Omit<React.HTMLProps<HTMLDivElemen
text?: React.ReactNode;
/** Icon rendered inside the toggle group item */
icon?: React.ReactNode;
/** Sets position of the icon */
tlabaj marked this conversation as resolved.
Show resolved Hide resolved
iconPosition?: 'start' | 'end';
/** Additional classes added to the toggle group item */
className?: string;
/** Flag indicating if the toggle group item is disabled */
Expand All @@ -25,6 +27,7 @@ export interface ToggleGroupItemProps extends Omit<React.HTMLProps<HTMLDivElemen
export const ToggleGroupItem: React.FunctionComponent<ToggleGroupItemProps> = ({
text,
icon,
iconPosition = 'start',
className,
isDisabled = false,
isSelected = false,
Expand Down Expand Up @@ -53,8 +56,13 @@ export const ToggleGroupItem: React.FunctionComponent<ToggleGroupItemProps> = ({
disabled={isDisabled}
id={buttonId}
>
{icon && <ToggleGroupItemElement variant={ToggleGroupItemVariant.icon}>{icon}</ToggleGroupItemElement>}
{icon && iconPosition === 'start' && (
<ToggleGroupItemElement variant={ToggleGroupItemVariant.icon}>{icon}</ToggleGroupItemElement>
tlabaj marked this conversation as resolved.
Show resolved Hide resolved
)}
{text && <ToggleGroupItemElement variant={ToggleGroupItemVariant.text}>{text}</ToggleGroupItemElement>}
{icon && iconPosition === 'end' && (
<ToggleGroupItemElement variant={ToggleGroupItemVariant.icon}>{icon}</ToggleGroupItemElement>
)}
</button>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,57 @@ export const ToggleGroupIcon: React.FunctionComponent = () => {
setIsSelected((prevIsSelected) => ({ ...prevIsSelected, [id]: isSelected }));
};
return (
<ToggleGroup aria-label="Text and icon toggle group">
<ToggleGroupItem
icon={<CopyIcon />}
text="Copy"
buttonId="toggle-group-text-icons-1"
isSelected={isSelected['toggle-group-text-icons-1']}
onChange={handleItemClick}
/>
<ToggleGroupItem
icon={<UndoIcon />}
text="Undo"
buttonId="toggle-group-text-icons-2"
isSelected={isSelected['toggle-group-text-icons-2']}
onChange={handleItemClick}
/>
<ToggleGroupItem
icon={<ShareSquareIcon />}
text="Share"
buttonId="toggle-group-text-icons-3"
isSelected={isSelected['toggle-group-text-icons-3']}
onChange={handleItemClick}
/>
</ToggleGroup>
<>
<ToggleGroup aria-label="Text and icon toggle group">
tlabaj marked this conversation as resolved.
Show resolved Hide resolved
<ToggleGroupItem
icon={<CopyIcon />}
text="Copy"
buttonId="toggle-group-text-icons-1"
isSelected={isSelected['toggle-group-text-icons-1']}
onChange={handleItemClick}
/>
<ToggleGroupItem
icon={<UndoIcon />}
text="Undo"
buttonId="toggle-group-text-icons-2"
isSelected={isSelected['toggle-group-text-icons-2']}
onChange={handleItemClick}
/>
<ToggleGroupItem
icon={<ShareSquareIcon />}
text="Share"
buttonId="toggle-group-text-icons-3"
isSelected={isSelected['toggle-group-text-icons-3']}
onChange={handleItemClick}
/>
</ToggleGroup>
<br />
<ToggleGroup aria-label="Text and icon toggle group">
tlabaj marked this conversation as resolved.
Show resolved Hide resolved
<ToggleGroupItem
icon={<CopyIcon />}
iconPosition="end"
text="Copy"
buttonId="toggle-group-text-icons-4"
isSelected={isSelected['toggle-group-text-icons-4']}
onChange={handleItemClick}
/>
<ToggleGroupItem
icon={<UndoIcon />}
iconPosition="end"
text="Undo"
buttonId="toggle-group-text-icons-5"
isSelected={isSelected['toggle-group-text-icons-5']}
onChange={handleItemClick}
/>
<ToggleGroupItem
icon={<ShareSquareIcon />}
iconPosition="end"
text="Share"
buttonId="toggle-group-text-icons-6"
isSelected={isSelected['toggle-group-text-icons-6']}
onChange={handleItemClick}
/>
</ToggleGroup>
</>
);
};
Loading