Skip to content

Commit 9ff752e

Browse files
committed
fix(Layout): issues
1 parent 76f3057 commit 9ff752e

File tree

5 files changed

+84
-13
lines changed

5 files changed

+84
-13
lines changed

src/components/content/Layout/Layout.stories.tsx

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { useState } from 'react';
22

33
import { Button, ItemButton } from '../../actions';
4+
import { Block } from '../../Block';
45
import { Space } from '../../layout/Space';
56
import { Text } from '../Text';
67
import { Title } from '../Title';
@@ -374,17 +375,13 @@ export const NestedLayouts: Story = {
374375
<Layout.Header title="Nested Layouts" />
375376
<Layout flow="row">
376377
<Layout width="200px" border="right">
377-
<Layout.Content padding="1x">
378+
<Layout.Content>
378379
<Text>Left sidebar</Text>
379380
</Layout.Content>
380381
</Layout>
381382
<Layout>
382-
<Layout.Toolbar>
383-
<Text>Inner toolbar</Text>
384-
</Layout.Toolbar>
385-
<Layout.Content padding="2x">
386-
<Text>Main content</Text>
387-
</Layout.Content>
383+
<Layout.Toolbar>Inner toolbar</Layout.Toolbar>
384+
<Layout.Content>Main content</Layout.Content>
388385
</Layout>
389386
</Layout>
390387
</Layout>
@@ -419,10 +416,8 @@ export const MultiplePanels: Story = {
419416
</Layout.Content>
420417
</Layout.Panel>
421418
<Layout.Toolbar>
422-
<Space>
423-
<Button onPress={() => setLeftOpen(!leftOpen)}>Left</Button>
424-
<Button onPress={() => setRightOpen(!rightOpen)}>Right</Button>
425-
</Space>
419+
<Button onPress={() => setLeftOpen(!leftOpen)}>Left</Button>
420+
<Button onPress={() => setRightOpen(!rightOpen)}>Right</Button>
426421
</Layout.Toolbar>
427422
<Layout.Content padding="2x">
428423
<Text>Main content between two panels</Text>
@@ -432,6 +427,27 @@ export const MultiplePanels: Story = {
432427
},
433428
};
434429

430+
export const HorizontalScrollableContent: Story = {
431+
render: () => (
432+
<Space width="500px" height="(5x - 2bw)">
433+
<Layout.Block fill="#light" placeSelf="center">
434+
Fixed Left
435+
</Layout.Block>
436+
<Layout.Content scrollbar="tiny" placeContent="center">
437+
<Text nowrap>
438+
This is a very long line of text that should not wrap and will cause
439+
horizontal scrolling when it exceeds the container width →→→→→→→→→→→
440+
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
441+
eiusmod tempor incididunt ut labore et dolore magna aliqua →→→→→→→→
442+
</Text>
443+
</Layout.Content>
444+
<Layout.Block fill="#light" placeSelf="center">
445+
Fixed Right
446+
</Layout.Block>
447+
</Space>
448+
),
449+
};
450+
435451
export const CompleteApplicationShell: Story = {
436452
render: function CompleteApplicationShellStory() {
437453
const [sidebarOpen, setSidebarOpen] = useState(true);
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import { ForwardedRef, forwardRef, ReactNode } from 'react';
2+
3+
import {
4+
BaseProps,
5+
CONTAINER_STYLES,
6+
ContainerStyleProps,
7+
extractStyles,
8+
filterBaseProps,
9+
tasty,
10+
} from '../../../tasty';
11+
12+
import { LayoutContextReset } from './LayoutContext';
13+
14+
const BlockElement = tasty({
15+
as: 'div',
16+
qa: 'LayoutBlock',
17+
styles: {
18+
display: 'block',
19+
padding: '($content-padding, 1x)',
20+
},
21+
});
22+
23+
export interface CubeLayoutBlockProps extends BaseProps, ContainerStyleProps {
24+
children?: ReactNode;
25+
}
26+
27+
function LayoutBlock(
28+
props: CubeLayoutBlockProps,
29+
ref: ForwardedRef<HTMLDivElement>,
30+
) {
31+
const { children, ...otherProps } = props;
32+
const styles = extractStyles(otherProps, CONTAINER_STYLES);
33+
34+
return (
35+
<BlockElement
36+
{...filterBaseProps(otherProps, { eventProps: true })}
37+
ref={ref}
38+
styles={styles}
39+
>
40+
<LayoutContextReset>{children}</LayoutContextReset>
41+
</BlockElement>
42+
);
43+
}
44+
45+
const _LayoutBlock = forwardRef(LayoutBlock);
46+
47+
_LayoutBlock.displayName = 'Layout.Block';
48+
49+
export { _LayoutBlock as LayoutBlock };

src/components/content/Layout/LayoutContent.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,13 @@ const ContentElement = tasty({
2424
minHeight: 0,
2525
overflow: 'hidden',
2626
boxSizing: 'border-box',
27+
placeSelf: 'stretch',
2728

2829
Inner: {
2930
position: 'absolute',
3031
inset: 0,
31-
display: 'block',
32+
display: 'flex',
33+
flow: 'column',
3234
padding: '($content-padding, 1x)',
3335
overflow: 'auto',
3436
scrollbar: {

src/components/content/Layout/LayoutToolbar.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const ToolbarElement = tasty({
2121
placeContent: 'center space-between',
2222
placeItems: 'center stretch',
2323
gap: '1x',
24-
padding: '1x 2x',
24+
padding: '($content-padding, 1x)',
2525
width: '100%',
2626
height: 'min 5x',
2727
overflow: 'hidden',

src/components/content/Layout/index.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { ForwardRefExoticComponent, RefAttributes } from 'react';
22

33
import { CubeLayoutProps, Layout as LayoutBase } from './Layout';
4+
import { LayoutBlock } from './LayoutBlock';
45
import { LayoutContent } from './LayoutContent';
56
import { LayoutFooter } from './LayoutFooter';
67
import { LayoutHeader } from './LayoutHeader';
@@ -11,6 +12,7 @@ import { LayoutToolbar } from './LayoutToolbar';
1112
export { GridLayout } from './GridLayout';
1213
export type { CubeGridLayoutProps } from './GridLayout';
1314
export type { CubeLayoutProps } from './Layout';
15+
export type { CubeLayoutBlockProps } from './LayoutBlock';
1416
export type { CubeLayoutContentProps, ScrollbarType } from './LayoutContent';
1517
export type { CubeLayoutFooterProps } from './LayoutFooter';
1618
export type { CubeLayoutHeaderProps } from './LayoutHeader';
@@ -29,6 +31,7 @@ interface LayoutComponent
2931
Header: typeof LayoutHeader;
3032
Footer: typeof LayoutFooter;
3133
Content: typeof LayoutContent;
34+
Block: typeof LayoutBlock;
3235
Panel: typeof LayoutPanel;
3336
PanelHeader: typeof LayoutPanelHeader;
3437
}
@@ -38,6 +41,7 @@ const Layout = Object.assign(LayoutBase, {
3841
Header: LayoutHeader,
3942
Footer: LayoutFooter,
4043
Content: LayoutContent,
44+
Block: LayoutBlock,
4145
Panel: LayoutPanel,
4246
PanelHeader: LayoutPanelHeader,
4347
}) as LayoutComponent;

0 commit comments

Comments
 (0)