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

chore: Add ActionButtonGroup and ToggleButtonGroup to example apps and tailwind starter kit #7407

Merged
merged 5 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
12 changes: 12 additions & 0 deletions examples/s2-parcel-example/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import React, { useState } from "react";
import "@react-spectrum/s2/page.css";
import {
ActionButton,
ActionButtonGroup,
ActionMenu,
Button,
ButtonGroup,
Expand All @@ -34,6 +35,7 @@ import {
TableView,
Text,
ToggleButton,
ToggleButtonGroup
} from "@react-spectrum/s2";
import Edit from "@react-spectrum/s2/icons/Edit";
import Section from "./components/Section";
Expand Down Expand Up @@ -100,6 +102,16 @@ function App() {
>
Link Button
</LinkButton>
<ActionButtonGroup density="compact">
<ActionButton>Cut</ActionButton>
<ActionButton>Copy</ActionButton>
<ActionButton>Paste</ActionButton>
</ActionButtonGroup>
<ToggleButtonGroup density="compact" selectionMode="multiple">
<ToggleButton id="bold">Bold</ToggleButton>
<ToggleButton id="italic">Italic</ToggleButton>
<ToggleButton id="underline">Underline</ToggleButton>
</ToggleButtonGroup>
</ButtonGroup>
</Section>

Expand Down
12 changes: 12 additions & 0 deletions examples/s2-vite-project/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import React, { useState } from "react";
import "@react-spectrum/s2/page.css";
import {
ActionButton,
ActionButtonGroup,
ActionMenu,
Button,
ButtonGroup,
Expand All @@ -34,6 +35,7 @@ import {
TableView,
Text,
ToggleButton,
ToggleButtonGroup
} from "@react-spectrum/s2";
import Edit from "@react-spectrum/s2/icons/Edit";
import Section from "./components/Section";
Expand Down Expand Up @@ -100,6 +102,16 @@ function App() {
>
Link Button
</LinkButton>
<ActionButtonGroup density="compact">
<ActionButton>Cut</ActionButton>
<ActionButton>Copy</ActionButton>
<ActionButton>Paste</ActionButton>
</ActionButtonGroup>
<ToggleButtonGroup density="compact" selectionMode="multiple">
<ToggleButton id="bold">Bold</ToggleButton>
<ToggleButton id="italic">Italic</ToggleButton>
<ToggleButton id="underline">Underline</ToggleButton>
</ToggleButtonGroup>
</ButtonGroup>
</Section>

Expand Down
12 changes: 12 additions & 0 deletions examples/s2-webpack-5-example/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import React, { useState } from "react";
import "@react-spectrum/s2/page.css";
import {
ActionButton,
ActionButtonGroup,
ActionMenu,
Button,
ButtonGroup,
Expand All @@ -34,6 +35,7 @@ import {
TableView,
Text,
ToggleButton,
ToggleButtonGroup
} from "@react-spectrum/s2";
import Edit from "@react-spectrum/s2/icons/Edit";
import Section from "./components/Section";
Expand Down Expand Up @@ -100,6 +102,16 @@ function App() {
>
Link Button
</LinkButton>
<ActionButtonGroup density="compact">
<ActionButton>Cut</ActionButton>
<ActionButton>Copy</ActionButton>
<ActionButton>Paste</ActionButton>
</ActionButtonGroup>
<ToggleButtonGroup density="compact" selectionMode="multiple">
<ToggleButton id="bold">Bold</ToggleButton>
<ToggleButton id="italic">Italic</ToggleButton>
<ToggleButton id="underline">Underline</ToggleButton>
</ToggleButtonGroup>
</ButtonGroup>
</Section>

Expand Down
2 changes: 1 addition & 1 deletion starters/tailwind/src/ToggleButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { focusRing } from './utils';

let styles = tv({
extend: focusRing,
base: 'px-5 py-2 text-sm text-center transition rounded-lg border border-black/10 dark:border-white/10 forced-colors:border-[ButtonBorder] shadow-[inset_0_1px_0_0_rgba(255,255,255,0.1)] dark:shadow-none cursor-default forced-color-adjust-none',
base: 'px-5 py-2 [&:has(svg:only-child)]:px-2 text-sm text-center transition rounded-lg border border-black/10 dark:border-white/10 forced-colors:border-[ButtonBorder] shadow-[inset_0_1px_0_0_rgba(255,255,255,0.1)] dark:shadow-none cursor-default forced-color-adjust-none',
variants: {
isSelected: {
false: 'bg-gray-100 hover:bg-gray-200 pressed:bg-gray-300 text-gray-800 dark:bg-zinc-600 dark:hover:bg-zinc-500 dark:pressed:bg-zinc-400 dark:text-zinc-100 forced-colors:!bg-[ButtonFace] forced-colors:!text-[ButtonText]',
Expand Down
21 changes: 21 additions & 0 deletions starters/tailwind/src/ToggleButtonGroup.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import React from 'react';
import { composeRenderProps, ToggleButtonGroup as RACToggleButtonGroup, ToggleButtonGroupProps } from 'react-aria-components';
import { tv } from 'tailwind-variants';

const styles = tv({
base: 'flex gap-1',
variants: {
orientation: {
horizontal: 'flex-row',
vertical: 'flex-col'
}
}
});

export function ToggleButtonGroup(props: ToggleButtonGroupProps) {
return (
<RACToggleButtonGroup
{...props}
className={composeRenderProps(props.className, (className) => styles({orientation: props.orientation || 'horizontal', className}))} />
);
}
27 changes: 27 additions & 0 deletions starters/tailwind/stories/ToggleButtonGroup.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import type { Meta } from '@storybook/react';
import React from 'react';
import { ToggleButton } from '../src/ToggleButton';
import { ToggleButtonGroup } from '../src/ToggleButtonGroup';
import { Bold, Italic, Underline } from 'lucide-react'

const meta: Meta<typeof ToggleButtonGroup> = {
component: ToggleButtonGroup,
parameters: {
layout: 'centered'
},
tags: ['autodocs']
};

export default meta;

export const Example = (args: any) => (
<ToggleButtonGroup {...args}>
<ToggleButton id="bold" aria-label="Bold"><Bold className="w-4 h-4" /></ToggleButton>
<ToggleButton id="italic" aria-label="Italic"><Italic className="w-4 h-4" /></ToggleButton>
<ToggleButton id="underline" aria-label="Underline"><Underline className="w-4 h-4" /></ToggleButton>
</ToggleButtonGroup>
);

Example.args = {
selectionMode: 'multiple'
};