Skip to content

Commit

Permalink
Content 7: Tooltip and Slider (#980)
Browse files Browse the repository at this point in the history
  • Loading branch information
vladmoroz authored Dec 6, 2024
1 parent b352ac3 commit 6210b46
Show file tree
Hide file tree
Showing 17 changed files with 477 additions and 14 deletions.
12 changes: 10 additions & 2 deletions docs/src/app/new/(content)/components/menu/page.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,21 @@ import { Menu } from '@base-ui-components/react/menu';
<Menu.RadioItem />
</Menu.RadioGroup>
<Menu.CheckboxItem />

{/* Submenu */}
<Menu.Root>
<Menu.SubmenuTrigger />
<Menu.Positioner>
<Menu.Popup>...</Menu.Popup>
</Menu.Positioner>
</Menu.Root>
</Menu.Popup>
</Menu.Positioner>
</Menu.Root>;
```

<Reference
component="Menu"
parts="Root, Trigger, Positioner, Popup, Arrow, Item, SubmenuTrigger, Group, GroupLabel, RadioGroup, RadioItem, RadioItemIndicator, CheckboxItem, CheckboxItemIndicator"
parts="Root, Trigger, Positioner, Popup, Arrow, Item, Group, GroupLabel, RadioGroup, RadioItem, RadioItemIndicator, CheckboxItem, CheckboxItemIndicator, SubmenuTrigger"
/>
{/* TODO: SubmenuTrigger and Separator are missing */}
{/* TODO: Separator is missing */}
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ export default function ExampleNumberField() {
</NumberField.ScrubArea>

<NumberField.Group className="flex">
<NumberField.Decrement className="flex h-10 w-10 items-center justify-center rounded-tl-md rounded-bl-md border border-gray-200 bg-gray-50 bg-clip-padding text-gray-900 select-none hover:bg-gray-100 active:bg-gray-100">
<NumberField.Decrement className="flex size-10 items-center justify-center rounded-tl-md rounded-bl-md border border-gray-200 bg-gray-50 bg-clip-padding text-gray-900 select-none hover:bg-gray-100 active:bg-gray-100">
<MinusIcon />
</NumberField.Decrement>
<NumberField.Input className="h-10 w-24 border-t border-b border-gray-200 text-center text-base text-gray-900 tabular-nums focus:z-1 focus:outline-2 focus:-outline-offset-1 focus:outline-blue-800" />
<NumberField.Increment className="flex h-10 w-10 items-center justify-center rounded-tr-md rounded-br-md border border-gray-200 bg-gray-50 bg-clip-padding text-gray-900 select-none hover:bg-gray-100 active:bg-gray-100">
<NumberField.Increment className="flex size-10 items-center justify-center rounded-tr-md rounded-br-md border border-gray-200 bg-gray-50 bg-clip-padding text-gray-900 select-none hover:bg-gray-100 active:bg-gray-100">
<PlusIcon />
</NumberField.Increment>
</NumberField.Group>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@
}
}

.Icon {
width: 1.25rem;
height: 1.25rem;
}

.Popup {
box-sizing: border-box;
padding: 1rem 1.5rem;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default function ExamplePopover() {
return (
<Popover.Root>
<Popover.Trigger className={styles.IconButton}>
<BellIcon aria-label="Notifications" />
<BellIcon aria-label="Notifications" className={styles.Icon} />
</Popover.Trigger>
<Popover.Positioner sideOffset={8}>
<Popover.Popup className={styles.Popup}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Popover } from '@base-ui-components/react/popover';
export default function ExamplePopover() {
return (
<Popover.Root>
<Popover.Trigger className="flex h-10 w-10 items-center justify-center rounded-md border border-gray-200 bg-gray-50 text-gray-900 select-none hover:bg-gray-100 focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-blue-800 active:bg-gray-100 data-[popup-open]:bg-gray-100">
<Popover.Trigger className="flex size-10 items-center justify-center rounded-md border border-gray-200 bg-gray-50 text-gray-900 select-none hover:bg-gray-100 focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-blue-800 active:bg-gray-100 data-[popup-open]:bg-gray-100">
<BellIcon aria-label="Notifications" />
</Popover.Trigger>
<Popover.Positioner sideOffset={8}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
}

.Link {
color: var(--color-gray-600);
font-size: 0.9375rem;
line-height: 1.375rem;
color: var(--color-gray-900);
text-decoration-color: var(--color-gray-400);
text-decoration-thickness: 1px;
text-decoration-line: none;
Expand All @@ -17,7 +19,6 @@
}

&:focus-visible {
color: var(--color-gray-900);
border-radius: 0.125rem;
outline: 2px solid var(--color-blue);
text-decoration-line: none;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,25 @@ export default function ExampleSeparator() {
<div className="flex gap-4">
<a
href="#"
className="text-gray-600 decoration-gray-400 decoration-1 underline-offset-2 outline-0 hover:underline focus-visible:rounded-sm focus-visible:text-gray-900 focus-visible:no-underline focus-visible:outline-2 focus-visible:outline-blue-800"
className="text-sm text-gray-900 decoration-gray-400 decoration-1 underline-offset-2 outline-0 hover:underline focus-visible:rounded-sm focus-visible:no-underline focus-visible:outline-2 focus-visible:outline-blue-800"
>
Home
</a>
<a
href="#"
className="text-gray-600 decoration-gray-400 decoration-1 underline-offset-2 outline-0 hover:underline focus-visible:rounded-sm focus-visible:text-gray-900 focus-visible:no-underline focus-visible:outline-2 focus-visible:outline-blue-800"
className="text-sm text-gray-900 decoration-gray-400 decoration-1 underline-offset-2 outline-0 hover:underline focus-visible:rounded-sm focus-visible:no-underline focus-visible:outline-2 focus-visible:outline-blue-800"
>
Pricing
</a>
<a
href="#"
className="text-gray-600 decoration-gray-400 decoration-1 underline-offset-2 outline-0 hover:underline focus-visible:rounded-sm focus-visible:text-gray-900 focus-visible:no-underline focus-visible:outline-2 focus-visible:outline-blue-800"
className="text-sm text-gray-900 decoration-gray-400 decoration-1 underline-offset-2 outline-0 hover:underline focus-visible:rounded-sm focus-visible:no-underline focus-visible:outline-2 focus-visible:outline-blue-800"
>
Blog
</a>
<a
href="#"
className="text-gray-600 decoration-gray-400 decoration-1 underline-offset-2 outline-0 hover:underline focus-visible:rounded-sm focus-visible:text-gray-900 focus-visible:no-underline focus-visible:outline-2 focus-visible:outline-blue-800"
className="text-sm text-gray-900 decoration-gray-400 decoration-1 underline-offset-2 outline-0 hover:underline focus-visible:rounded-sm focus-visible:no-underline focus-visible:outline-2 focus-visible:outline-blue-800"
>
Support
</a>
Expand All @@ -33,13 +33,13 @@ export default function ExampleSeparator() {

<a
href="#"
className="text-gray-600 decoration-gray-400 decoration-1 underline-offset-2 outline-0 hover:underline focus-visible:rounded-sm focus-visible:text-gray-900 focus-visible:no-underline focus-visible:outline-2 focus-visible:outline-blue-800"
className="text-sm text-gray-900 decoration-gray-400 decoration-1 underline-offset-2 outline-0 hover:underline focus-visible:rounded-sm focus-visible:no-underline focus-visible:outline-2 focus-visible:outline-blue-800"
>
Log in
</a>
<a
href="#"
className="text-gray-600 decoration-gray-400 decoration-1 underline-offset-2 outline-0 hover:underline focus-visible:rounded-sm focus-visible:text-gray-900 focus-visible:no-underline focus-visible:outline-2 focus-visible:outline-blue-800"
className="text-sm text-gray-900 decoration-gray-400 decoration-1 underline-offset-2 outline-0 hover:underline focus-visible:rounded-sm focus-visible:no-underline focus-visible:outline-2 focus-visible:outline-blue-800"
>
Sign up
</a>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
.Control {
box-sizing: border-box;
display: flex;
align-items: center;
width: 14rem;
padding-block: 0.75rem;
}

.Track {
width: 100%;
background-color: var(--color-gray-200);
box-shadow: inset 0 0 0 1px var(--color-gray-200);
height: 0.25rem;
border-radius: 0.25rem;
position: relative;
}

.Indicator {
/* TODO remove relative when position absolute is removed */
position: relative !important;
display: block;
border-radius: 0.25rem;
background-color: var(--color-gray-700);
}

.Thumb {
width: 1rem;
height: 1rem;
border-radius: 100%;
background-color: white;
outline: 1px solid var(--color-gray-300);

&:focus-visible {
outline: 2px solid var(--color-blue);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import * as React from 'react';
import { Slider } from '@base-ui-components/react/slider';
import styles from './index.module.css';

export default function ExampleSlider() {
return (
<Slider.Root defaultValue={25}>
<Slider.Control className={styles.Control}>
<Slider.Track className={styles.Track}>
<Slider.Indicator className={styles.Indicator} />
<Slider.Thumb className={styles.Thumb} />
</Slider.Track>
</Slider.Control>
</Slider.Root>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use client';
export { default as CssModules } from './css-modules';
export { default as Tailwind } from './tailwind';
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import * as React from 'react';
import { Slider } from '@base-ui-components/react/slider';

export default function ExampleSlider() {
return (
<Slider.Root defaultValue={25}>
<Slider.Control className="flex w-56 items-center px-2 py-3">
<Slider.Track className="relative h-1 w-full rounded bg-gray-200 shadow-[inset_0_0_0_1px] shadow-gray-200">
{/* TODO remove relative when position absolute is removed */}
<Slider.Indicator className="!relative block rounded bg-gray-700" />
<Slider.Thumb className="size-4 rounded-full bg-white outline outline-gray-300 focus-visible:outline-2 focus-visible:outline-blue-800" />
</Slider.Track>
</Slider.Control>
</Slider.Root>
);
}
29 changes: 29 additions & 0 deletions docs/src/app/new/(content)/components/slider/page.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Slider

<Subtitle>An easily stylable range input.</Subtitle>
<Meta
name="description"
content="A high-quality, unstyled React slider component that works like a range input and is easy to style."
/>

<Demo path="./demos/hero" />

## API reference

Import the component and place its parts the following way:

```jsx title="Anatomy"
import { Slider } from '@base-ui-components/react/slider';

<Slider.Root>
<Slider.Output />
<Slider.Control>
<Slider.Track>
<Slider.Indicator />
<Slider.Thumb />
</Slider.Track>
</Slider.Control>
</Slider.Root>;
```

<Reference component="Slider" parts="Root, Output, Control, Track, Indicator, Thumb" />
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
.Group {
display: flex;
border: 1px solid var(--color-gray-200);
background-color: var(--color-gray-50);
border-radius: 0.375rem;
padding: 0.125rem;
}

.GhostButton {
box-sizing: border-box;
display: flex;
align-items: center;
justify-content: center;
width: 2rem;
height: 2rem;
padding: 0;
margin: 0;
outline: 0;
border: 0;
border-radius: 0.25rem;
background-color: transparent;
color: var(--color-gray-900);
user-select: none;

&[data-popup-open] {
background-color: var(--color-gray-100);
}

&:focus-visible {
background-color: transparent;
outline: 2px solid var(--color-blue);
outline-offset: -1px;
}

@media (hover: hover) {
&:hover {
background-color: var(--color-gray-100);
}
}

&:active {
background-color: var(--color-gray-200);
}
}

.Icon {
width: 1rem;
height: 1rem;
}

.Popup {
box-sizing: border-box;
font-size: 0.9375rem;
line-height: 1.375rem;
display: flex;
flex-direction: column;
padding: 0.25rem 0.5rem;
border-radius: 0.375rem;
background-color: canvas;
transform-origin: var(--transform-origin);
transition:
transform 150ms,
opacity 150ms;

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

&[data-instant] {
transition-duration: 0ms;
}

@media (prefers-color-scheme: light) {
outline: 1px solid var(--color-gray-200);
box-shadow:
0px 10px 15px -3px var(--color-gray-200),
0px 4px 6px -4px var(--color-gray-200);
}

@media (prefers-color-scheme: dark) {
outline: 1px solid var(--color-gray-300);
outline-offset: -1px;
}
}

.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 {
@media (prefers-color-scheme: light) {
fill: var(--color-gray-200);
}
}

.ArrowInnerStroke {
@media (prefers-color-scheme: dark) {
fill: var(--color-gray-300);
}
}
Loading

0 comments on commit 6210b46

Please sign in to comment.