diff --git a/app/components/Collapsible.tsx b/app/components/Collapsible.tsx new file mode 100644 index 0000000000..b36af8006f --- /dev/null +++ b/app/components/Collapsible.tsx @@ -0,0 +1,112 @@ +import * as RadixCollapsible from "@radix-ui/react-collapsible"; +import { ExpandedIcon } from "outline-icons"; +import * as React from "react"; +import styled from "styled-components"; +import { s } from "@shared/styles"; + +interface CollapsibleProps { + /** The label displayed on the trigger button. */ + label: React.ReactNode; + /** The content to show/hide inside the collapsible panel. */ + children: React.ReactNode; + /** Whether the collapsible is open by default. */ + defaultOpen?: boolean; + /** Controlled open state. */ + open?: boolean; + /** Callback fired when the open state changes. */ + onOpenChange?: (open: boolean) => void; + /** Additional class name for the root element. */ + className?: string; +} + +/** + * An accessible collapsible section built on Radix UI Collapsible. + * Renders a trigger button with a disclosure chevron and animated content panel. + * + * @param props - component props. + * @returns the collapsible component. + */ +export function Collapsible({ + label, + children, + defaultOpen = false, + open, + onOpenChange, + className, +}: CollapsibleProps) { + return ( + + + + {children} + + ); +} + +const StyledExpandedIcon = styled(ExpandedIcon)` + flex-shrink: 0; + transition: transform 150ms ease-out; + margin-left: -4px; +`; + +const StyledTrigger = styled(RadixCollapsible.Trigger)` + display: flex; + align-items: center; + background: none; + border: none; + padding: 0 0 8px 0; + cursor: var(--pointer); + color: ${s("textTertiary")}; + font-size: 14pxte + + &:hover { + color: ${s("textSecondary")}; + } + + &[data-state="closed"] { + ${StyledExpandedIcon} { + transform: rotate(-90deg); + } + } +`; + +const StyledContent = styled(RadixCollapsible.Content)` + overflow: hidden; + + &[data-state="open"] { + animation: slideDown 200ms ease-out; + } + + &[data-state="closed"] { + animation: slideUp 200ms ease-out; + } + + @keyframes slideDown { + from { + height: 0; + opacity: 0; + } + to { + height: var(--radix-collapsible-content-height); + opacity: 1; + } + } + + @keyframes slideUp { + from { + height: var(--radix-collapsible-content-height); + opacity: 1; + } + to { + height: 0; + opacity: 0; + } + } +`; diff --git a/app/components/Collection/CollectionForm.tsx b/app/components/Collection/CollectionForm.tsx index bbdd458939..a00bf9227c 100644 --- a/app/components/Collection/CollectionForm.tsx +++ b/app/components/Collection/CollectionForm.tsx @@ -13,6 +13,7 @@ import { colorPalette } from "@shared/utils/collections"; import { CollectionValidation } from "@shared/validations"; import type Collection from "~/models/Collection"; import Button from "~/components/Button"; +import { Collapsible } from "~/components/Collapsible"; import Input from "~/components/Input"; import { InputSelectPermission } from "~/components/InputSelectPermission"; import { createLazyComponent } from "~/components/LazyLoad"; @@ -144,7 +145,7 @@ export const CollectionForm = observer(function CollectionForm_({ )} - {team.sharing && ( - ( - + {team.sharing && ( + ( + )} - checked={field.value} - onChange={field.onChange} /> )} - /> - )} - {team.getPreference(TeamPreference.Commenting) && ( - ( - ( + + )} /> )} - /> + )} diff --git a/shared/i18n/locales/en_US/translation.json b/shared/i18n/locales/en_US/translation.json index 43f6b1dbb8..fd84cb8b07 100644 --- a/shared/i18n/locales/en_US/translation.json +++ b/shared/i18n/locales/en_US/translation.json @@ -197,6 +197,7 @@ "Collections are used to group documents and choose permissions": "Collections are used to group documents and choose permissions", "Name": "Name", "The default access for workspace members, you can share with more users or groups later.": "The default access for workspace members, you can share with more users or groups later.", + "Advanced options": "Advanced options", "Public document sharing": "Public document sharing", "Allow documents within this collection to be shared publicly on the internet.": "Allow documents within this collection to be shared publicly on the internet.", "Commenting": "Commenting",