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

[experiments] Fluent UI submenus #1319

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
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
46 changes: 46 additions & 0 deletions docs/src/app/(private)/experiments/composite.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
.Grid {
display: flex;
flex-direction: column;
box-sizing: border-box;
padding-block: 0.25rem;
background-color: canvas;
color: oklch(12% 5% 264 / 90%);
transform-origin: var(--transform-origin);
transition:
transform 150ms,
opacity 150ms;

&[data-starting-style],
&[data-ending-style] {
opacity: 0;
transform: scale(0.9);
}

outline: 1px solid oklch(12% 9% 264 / 8%);
box-shadow:
0px 4px 6px -3px oklch(12% 9% 264 / 8%),
0px 4px 6px -4px oklch(12% 9% 264 / 8%);
}

.GridRow {
display: flex;
}

.GridItem {
outline: 0;
cursor: default;
display: flex;
align-items: center;
justify-content: center;
width: 48px;
height: 48px;
&:hover {
background: oklch(12% 9.5% 264 / 5%);
}

&[data-highlighted] {
z-index: 0;
position: relative;
background: oklch(12% 9.5% 264 / 5%);
}
}
81 changes: 81 additions & 0 deletions docs/src/app/(private)/experiments/composite.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
'use client';
import * as React from 'react';
import { Composite } from '@base-ui-components/react/composite';
import styles from './composite.module.css';

export default function ExampleGrid() {
const [column, setColumn] = React.useState(0);
const [row, setRow] = React.useState(0);

const rootHandleHighligtedIndexChange = (index: number) => {
setRow(index);
};

const handleHighligtedIndexChange = (index: number) => {
setColumn(index);
};

return (
<Composite.Root
highlightedIndex={row}
onHighlightedIndexChange={rootHandleHighligtedIndexChange}
orientation="vertical"
className={styles.Grid}
>
<Composite.Item>
<Composite.Root
highlightedIndex={row === 0 ? column : -1}
onHighlightedIndexChange={handleHighligtedIndexChange}
loop={false}
orientation="horizontal"
className={styles.GridRow}
>
<Composite.Item className={styles.GridItem}>A</Composite.Item>
<Composite.Item className={styles.GridItem}>B</Composite.Item>
<Composite.Item className={styles.GridItem}>C</Composite.Item>
<Composite.Item className={styles.GridItem}>D</Composite.Item>
</Composite.Root>
</Composite.Item>
<Composite.Item>
<Composite.Root
highlightedIndex={row === 1 ? column : -1}
onHighlightedIndexChange={handleHighligtedIndexChange}
loop={false}
orientation="horizontal"
className={styles.GridRow}
>
<Composite.Item className={styles.GridItem}>E</Composite.Item>
<Composite.Item className={styles.GridItem}>F</Composite.Item>
<Composite.Item className={styles.GridItem}>G</Composite.Item>
<Composite.Item className={styles.GridItem}>H</Composite.Item>
</Composite.Root>
</Composite.Item>
<Composite.Item>
<Composite.Root
highlightedIndex={row === 2 ? column : -1}
onHighlightedIndexChange={handleHighligtedIndexChange}
loop={false}
orientation="horizontal"
className={styles.GridRow}
>
<Composite.Item className={styles.GridItem}>I</Composite.Item>
<Composite.Item className={styles.GridItem}>J</Composite.Item>
<Composite.Item className={styles.GridItem}>K</Composite.Item>
<Composite.Item className={styles.GridItem}>L</Composite.Item>
</Composite.Root>
</Composite.Item>
<Composite.Item>
<Composite.Root
highlightedIndex={row === 3 ? column : -1}
onHighlightedIndexChange={handleHighligtedIndexChange}
loop={false}
orientation="horizontal"
className={styles.GridRow}
>
<Composite.Item className={styles.GridItem}>M</Composite.Item>
<Composite.Item className={styles.GridItem}>N</Composite.Item>
</Composite.Root>
</Composite.Item>
</Composite.Root>
);
}
174 changes: 174 additions & 0 deletions docs/src/app/(private)/experiments/menu-fluent-ui.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
.Button {
width: fit-content;
box-sizing: border-box;
font-size: 0.875rem;
display: flex;
align-items: center;
justify-content: center;
gap: 0.375rem;
height: 2rem;
padding: 0 1rem;
margin: 0;
outline: 0;
border: 1px solid oklch(12% 9% 264 / 8%);
background-color: oklch(98% 0.25% 264);
font-family: inherit;
font-weight: 500;
line-height: 1.5rem;
color: oklch(12% 5% 264 / 90%);
user-select: none;

@media (hover: hover) {
&:hover {
background-color: oklch(12% 9.5% 264 / 5%);
}
}

&:active {
background-color: oklch(12% 9.5% 264 / 5%);
}

&[data-popup-open] {
background-color: oklch(12% 9.5% 264 / 5%);
}

&:focus-visible {
outline: 2px solid oklch(45% 50% 264);
outline-offset: -1px;
}
}

.Positioner {
outline: 0;
}

.Popup,
.Grid {
box-sizing: border-box;
padding-block: 0.25rem;
background-color: canvas;
color: oklch(12% 5% 264 / 90%);
transform-origin: var(--transform-origin);
transition:
transform 150ms,
opacity 150ms;

&[data-starting-style],
&[data-ending-style] {
opacity: 0;
transform: scale(0.9);
}

outline: 1px solid oklch(12% 9% 264 / 8%);
box-shadow:
0px 4px 6px -3px oklch(12% 9% 264 / 8%),
0px 4px 6px -4px oklch(12% 9% 264 / 8%);
}

.Arrow {
display: flex;

&[data-side='top'] {
bottom: -8px;
rotate: 180deg;
}
&[data-side='bottom'] {
top: -8px;
rotate: 0deg;
}
&[data-side='left'] {
right: -13px;
rotate: 90deg;
}
&[data-side='right'] {
left: -13px;
rotate: -90deg;
}
}

.ArrowFill {
fill: canvas;
}

.ArrowOuterStroke {
fill: oklch(12% 9% 264 / 8%);
}

.Separator {
margin: 0.375rem 0;
height: 1px;
background-color: oklch(12% 9% 264 / 8%);
}

.Item,
.ItemWithSubmenu,
.SubmenuTriggerInsideItem,
.SplitButtonItem,
.SplitButtonSubmenuTrigger {
outline: 0;
cursor: default;
user-select: none;
padding-block: 0.5rem;
padding-left: 1rem;
padding-right: 2rem;
display: flex;
font-size: 0.875rem;
line-height: 1rem;
align-items: center;
justify-content: space-between;
gap: 1rem;
padding-right: 1rem;

&[data-highlighted] {
z-index: 0;
position: relative;
background: oklch(12% 9.5% 264 / 5%);
}
}

.ItemWithSubmenu {
padding-right: 0;
padding-block: 0;
}

.SubmenuTrigger {
padding: 0.75rem 1rem;
margin-left: auto;
}

.SplitButtonItem {
display: inline-flex;
padding-left: 1rem;
}

.SplitButtonSubmenuTrigger {
padding-top: 0.75rem;
padding-bottom: 0.75rem;
display: inline-flex;
}

.Grid {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 0.25rem;
}

.GridRow {
display: flex;
}

.GridItem {
outline: 0;
cursor: default;
display: flex;
align-items: center;
justify-content: center;
width: 48px;
height: 48px;

&[data-highlighted] {
z-index: 0;
position: relative;
background: oklch(12% 9.5% 264 / 5%);
}
}
Loading
Loading