Skip to content
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 .changeset/banner-solid-sticky.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
'@wirecore/wirelayer-recipes': minor
'@wirecore/wirelayer-css': minor
'@wirecore/wirelayer-vue': minor
'@wirecore/wirelayer-react': minor
'@wirecore/wirelayer-native': minor
---

Banner for permanent, page-wide notices ("TEST SYSTEM", maintenance): `solid` fills it opaquely in the colour of the
variant with the matching text colour (info → `bg-info text-on-info`, …, neutral → `bg-fg text-bg`); `position="sticky"`
keeps it in the flow and at the top edge while the page scrolls (opaque also without `solid`, below dialogs and
drawers). React Native gets `solid` (no `sticky`). Stories _Solid_ and _Sticky_.
7 changes: 7 additions & 0 deletions .changeset/tabs-lazy-mount-keeps-panel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@wirecore/wirelayer-vue': patch
---

Tabs with `lazyMount`: the panel that was open when the tabs mounted stays mounted (hidden) when its tab is left, as
documented – only `unmountOnExit` removes a panel again. Ark's Vue presence forgot that panel and removed it, so e.g.
form fields in it were gone on submit. TabsContent now mounts the panels itself with the same rules.
8 changes: 8 additions & 0 deletions .changeset/textarea-autoresize-hidden.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
'@wirecore/wirelayer-vue': patch
'@wirecore/wirelayer-react': patch
---

Textarea with `autoResize`: measures its height again once it becomes visible and whenever its width changes. Mounted
hidden (an inactive tab, a closed accordion, a popover before it opens) it measured 0 and stayed one line high. A
hidden textarea now keeps its rows until it can be measured. Story _Textarea in Tabs_.
26 changes: 22 additions & 4 deletions packages/mcp/data/components.json
Original file line number Diff line number Diff line change
Expand Up @@ -2233,7 +2233,13 @@
"name": "position",
"type": "BannerPosition",
"optional": true,
"description": "`inline` (default): in the flow; `top`/`bottom`: fixed to that edge of the window"
"description": "`inline` (default): in the flow; `top`/`bottom`: fixed to that edge of the window; `sticky`: in the flow, stays at the top edge while the page scrolls (opaque, below dialogs and drawers)"
},
{
"name": "solid",
"type": "boolean",
"optional": true,
"description": "Full fill in the colour of the variant (opaque) – for permanent notices like \"TEST SYSTEM\" or maintenance"
},
{
"name": "dismissible",
Expand Down Expand Up @@ -2314,7 +2320,13 @@
"name": "position",
"type": "BannerPosition",
"optional": true,
"description": "`inline` (default): in the flow; `top`/`bottom`: fixed to that edge of the window"
"description": "`inline` (default): in the flow; `top`/`bottom`: fixed to that edge of the window; `sticky`: in the flow, stays at the top edge while the page scrolls (opaque, below dialogs and drawers)"
},
{
"name": "solid",
"type": "boolean",
"optional": true,
"description": "Full fill in the colour of the variant (opaque) – for permanent notices like \"TEST SYSTEM\" or maintenance"
},
{
"name": "dismissible",
Expand Down Expand Up @@ -38863,9 +38875,15 @@
},
{
"name": "position",
"type": "BannerPosition",
"type": "Exclude<BannerPosition, 'sticky'>",
"optional": true,
"description": "`inline` (default) in the layout, `top`/`bottom` over that edge of the screen (`sticky` is web only)"
},
{
"name": "solid",
"type": "boolean",
"optional": true,
"description": "`inline` (default) in the layout, `top`/`bottom` over that edge of the screen"
"description": "Full fill in the colour of the variant (opaque) – for permanent notices like \"TEST SYSTEM\" or maintenance"
},
{
"name": "dismissible",
Expand Down
24 changes: 24 additions & 0 deletions packages/native/src/components/Banner/Banner.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,27 @@ export const Variants: Story = {
</View>
),
};

/** Full fill in the colour of the variant – for permanent notices like "TEST SYSTEM" */
export const Solid: Story = {
name: 'Solid',
render: () => (
<View className="gap-3">
<Banner variant="info" solid>
New: download invoices as PDF.
</Banner>
<Banner variant="success" solid title="Saved">
Your changes are live.
</Banner>
<Banner variant="warn" solid title="TEST SYSTEM" dismissible>
Data is reset every night.
</Banner>
<Banner variant="danger" solid title="Outage">
Payments are currently not being processed.
</Banner>
<Banner variant="neutral" solid>
Trial ends in 5 days.
</Banner>
</View>
),
};
9 changes: 6 additions & 3 deletions packages/native/src/components/Banner/Banner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ export interface BannerProps extends ViewProps {
variant?: BannerVariant;
/** Bold text before the message */
title?: string;
/** `inline` (default) in the layout, `top`/`bottom` over that edge of the screen */
position?: BannerPosition;
/** `inline` (default) in the layout, `top`/`bottom` over that edge of the screen (`sticky` is web only) */
position?: Exclude<BannerPosition, 'sticky'>;
/** Full fill in the colour of the variant (opaque) – for permanent notices like "TEST SYSTEM" or maintenance */
solid?: boolean;
/** Shows a close button */
dismissible?: boolean;
/** Controlled visibility */
Expand Down Expand Up @@ -40,6 +42,7 @@ export function Banner({
variant = 'info',
title,
position,
solid = false,
dismissible = false,
open,
onOpenChange,
Expand All @@ -54,7 +57,7 @@ export function Banner({
}: BannerProps) {
const translations = useTranslations();
const [internal, setInternal] = useState(true);
const styles = banner({ variant, position });
const styles = banner({ variant, position, solid });
if (!(open ?? internal)) return null;
const dismiss = () => {
setInternal(false);
Expand Down
14 changes: 14 additions & 0 deletions packages/parity/e2e/controls.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,20 @@ test.describe('Textarea', () => {
expect(scroll).toBeLessThanOrEqual(1);
});

test('autoResize in a tab that was hidden when it mounted: as high as its text once the tab opens', async ({
page,
}) => {
await openStory(page, 'forms-textarea--in-tabs');
await page.getByRole('tab', { name: 'Notes' }).click();
const area = page.getByRole('textbox', { name: 'Notes' });
await expect(area).toBeVisible();
// Four lines, not one: the height was measured again once the tab became visible
const line = await area.evaluate((element) => parseFloat(getComputedStyle(element).lineHeight));
await expect.poll(async () => (await area.boundingBox())!.height).toBeGreaterThan(3 * line);
const scroll = await area.evaluate((element) => element.scrollHeight - element.clientHeight);
expect(scroll).toBeLessThanOrEqual(1);
});

test('defaultValue arrives without v-model; the counter counts it', async ({ page }) => {
await openStory(page, 'forms-textarea--initial-value');
const area = page.getByRole('textbox', { name: 'Comment' });
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
42 changes: 42 additions & 0 deletions packages/parity/src/behavior.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,48 @@ describe.each(frameworks)('%s', (framework) => {
expect(screen.getByRole('tab', { name: 'Process' })).toHaveAttribute('aria-selected', 'true');
expect(screen.getByRole('tabpanel', { name: 'Process' })).toHaveTextContent('Content B');
});

it.each([
// lazyMount: a panel from its first selection on, kept (hidden) when its tab is left
[{ lazyMount: true }, { a: true, c: false }],
// unmountOnExit as well: removed again when its tab is left
[
{ lazyMount: true, unmountOnExit: true },
{ a: false, c: false },
],
// Neither: every panel is there from the start
[{}, { a: true, c: true }],
])('%o: which panels stay in the DOM after a switch from A to B', async (props, expected) => {
await render(
framework,
el(
'Tabs',
{ defaultValue: 'a', label: 'Project', ...props },
el(
'TabsList',
{},
el('TabsTrigger', { value: 'a' }, 'Overview'),
el('TabsTrigger', { value: 'b' }, 'Process'),
el('TabsTrigger', { value: 'c' }, 'Team')
),
el('TabsContent', { value: 'a' }, 'Content A'),
el('TabsContent', { value: 'b' }, 'Content B'),
el('TabsContent', { value: 'c' }, 'Content C')
)
);
await userEvent.click(screen.getByRole('tab', { name: 'Process' }));
expect(screen.getByRole('tabpanel', { name: 'Process' })).toHaveTextContent('Content B');
// Ark hides or removes the panel that was left once its exit finished
await waitFor(() => {
const a = screen.queryByText('Content A');
expect(!!a).toBe(expected.a);
if (a) expect(a).not.toBeVisible();
});
expect(!!screen.queryByText('Content C')).toBe(expected.c);
// Back on A: shown again either way
await userEvent.click(screen.getByRole('tab', { name: 'Overview' }));
expect(screen.getByRole('tabpanel', { name: 'Overview' })).toHaveTextContent('Content A');
});
});

describe('Steps', () => {
Expand Down
9 changes: 9 additions & 0 deletions packages/parity/src/cases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2263,6 +2263,15 @@ export const cases: [string, El][] = [
'Banner without icon, bottom',
el('Banner', { hideIcon: true, position: 'bottom', dismissLabel: 'Dismiss' }, 'Cookies'),
],
...(['info', 'success', 'warn', 'danger', 'neutral'] as const).map((variant): [string, El] => [
`Banner ${variant} solid`,
el('Banner', { variant, solid: true, dismissible: true, title: 'Test system' }, 'Data is reset every night.'),
]),
['Banner sticky', el('Banner', { variant: 'warn', position: 'sticky' }, 'Maintenance on Saturday.')],
[
'Banner sticky solid',
el('Banner', { variant: 'warn', position: 'sticky', solid: true, title: 'TEST SYSTEM' }, 'Not for real data.'),
],
...(['success', 'info', 'warn', 'error', '403', '404', '500'] as const).map((status): [string, El] => [
`Result ${status}`,
el('Result', { status }),
Expand Down
41 changes: 40 additions & 1 deletion packages/react/src/components/Banner/Banner.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const meta = {
},
argTypes: {
variant: { control: 'inline-radio', options: ['info', 'success', 'warn', 'danger', 'neutral'] },
position: { control: 'inline-radio', options: ['inline', 'top', 'bottom'] },
position: { control: 'inline-radio', options: ['inline', 'top', 'bottom', 'sticky'] },
},
parameters: { layout: 'fullscreen' },
} satisfies Meta<typeof Banner>;
Expand Down Expand Up @@ -75,3 +75,42 @@ export const Top: Story = {
</div>
),
};

/** Full fill in the colour of the variant – for permanent notices; the close button and icon take the text colour */
export const Solid: Story = {
render: () => (
<div className="flex flex-col gap-3">
<Banner variant="info" solid>
New features in the customer portal – available to everyone today.
</Banner>
<Banner variant="success" solid title="Done">
Your data has been transferred.
</Banner>
<Banner variant="warn" solid title="TEST SYSTEM" dismissible>
Data is reset every night.
</Banner>
<Banner variant="danger" solid title="Outage">
Payment processing is down. We are working on it.
</Banner>
<Banner variant="neutral" solid>
Trial ends in 5 days.
</Banner>
</div>
),
};

/** In the flow above the content, stays at the top edge while the page scrolls – opaque, also without solid */
export const Sticky: Story = {
render: () => (
<div className="h-72 overflow-y-auto" tabIndex={0} role="region" aria-label="Page">
<Banner variant="warn" position="sticky" solid title="TEST SYSTEM">
Not for real data.
</Banner>
<div className="flex flex-col gap-3 p-6 text-sm text-muted">
{Array.from({ length: 12 }, (_, index) => (
<p key={index}>Page content, row {index + 1} – scroll down, the banner stays.</p>
))}
</div>
</div>
),
};
10 changes: 8 additions & 2 deletions packages/react/src/components/Banner/Banner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,13 @@ export interface BannerProps extends Omit<ComponentProps<'div'>, 'title'> {
variant?: BannerVariant;
/** Bold text before the message */
title?: string;
/** `inline` (default): in the flow; `top`/`bottom`: fixed to that edge of the window */
/**
* `inline` (default): in the flow; `top`/`bottom`: fixed to that edge of the window; `sticky`: in the flow, stays at
* the top edge while the page scrolls (opaque, below dialogs and drawers)
*/
position?: BannerPosition;
/** Full fill in the colour of the variant (opaque) – for permanent notices like "TEST SYSTEM" or maintenance */
solid?: boolean;
/** Shows a close button */
dismissible?: boolean;
/** Controlled visibility */
Expand Down Expand Up @@ -56,6 +61,7 @@ export function Banner({
variant,
title,
position,
solid,
dismissible,
open,
onOpenChange,
Expand All @@ -70,7 +76,7 @@ export function Banner({
...props
}: BannerProps) {
const banner = useRecipe('banner', bannerRecipe, classes);
const styles = banner({ variant, position });
const styles = banner({ variant, position, solid });
const translations = useTranslations();
const [internal, setInternal] = useState(true);
// A remembered dismissal is only known in the browser (after the server-rendered first paint)
Expand Down
24 changes: 24 additions & 0 deletions packages/react/src/components/Textarea/Textarea.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { Meta, StoryObj } from '@storybook/react-vite';
import { useState } from 'react';
import { Field } from '../Field/Field.js';
import { Tabs, TabsContent, TabsList, TabsTrigger } from '../Tabs/Tabs.js';
import { Textarea, type TextareaProps } from './Textarea.js';

function Demo(args: TextareaProps) {
Expand Down Expand Up @@ -89,3 +90,26 @@ export const SizesAndStates: Story = {
</div>
),
};

function InTabsDemo() {
const [text, setText] = useState('Line 1\nLine 2\nLine 3\nLine 4');
return (
<Tabs defaultValue="general" label="Profile" className="w-80">
<TabsList>
<TabsTrigger value="general">General</TabsTrigger>
<TabsTrigger value="notes">Notes</TabsTrigger>
</TabsList>
<TabsContent value="general" className="text-sm text-muted">
Name and e-mail address.
</TabsContent>
<TabsContent value="notes">
<Field label="Notes">
<Textarea value={text} onChange={(event) => setText(event.target.value)} autoResize rows={1} />
</Field>
</TabsContent>
</Tabs>
);
}

/** In a tab that is hidden when it mounts: measures its height once the tab opens */
export const InTabs: Story = { name: 'Textarea in Tabs', render: () => <InTabsDemo /> };
22 changes: 21 additions & 1 deletion packages/react/src/components/Textarea/Textarea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ export function Textarea({
const area = element.current;
if (!autoResize || !area) return;
area.style.height = 'auto';
// Hidden (inactive tab, closed accordion …) it measures 0: keep the rows until it is visible
if (!area.scrollHeight) return;
const border = area.offsetHeight - area.clientHeight;
let height = area.scrollHeight + border;
if (minRows || maxRows) {
Expand All @@ -103,7 +105,25 @@ export function Textarea({
}
area.style.height = `${height}px`;
};
useLayoutEffect(resize);
const latestResize = useRef(resize);
useLayoutEffect(() => {
latestResize.current = resize;
resize();
});
// Measured again when it gets a width (it becomes visible) and when the width changes (the text wraps differently)
useLayoutEffect(() => {
const area = element.current;
if (!autoResize || !area || typeof ResizeObserver === 'undefined') return;
let observedWidth = 0;
const observer = new ResizeObserver(([entry]) => {
const width = entry?.contentRect.width ?? 0;
if (width === observedWidth) return;
observedWidth = width;
if (width) latestResize.current();
});
observer.observe(area);
return () => observer.disconnect();
}, [autoResize, wrapped]);

// Counter: announced politely once typing pauses
const counterId = useId();
Expand Down
Loading
Loading