Skip to content

Commit 2e2ce19

Browse files
author
Luke Bowerman
authored
Layout (semantic) improvements (#1448)
* Remove `Main` (use `as="main"` on `Section` instead) * Various flex configuration improvements * Storybook story fixes
1 parent 566c6c4 commit 2e2ce19

File tree

8 files changed

+43
-64
lines changed

8 files changed

+43
-64
lines changed

CHANGELOG.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
- `TabList` now supports `PaddingProps` and `fontSize`
1111
- `TabList` w/ `distribute` now uses default "small" `fontSize`
1212

13-
- Preview: `InputFilters` component and tests (this component is not yet ready for general-use)
14-
- Preview: `ActionListControls` component (this component is not yet ready for general-use)
15-
- Experimental: `@looker/components-theme-editor` package
13+
* Preview: `InputFilters` component and tests (this component is not yet ready for general-use)
14+
* Preview: `ActionListControls` component (this component is not yet ready for general-use)
15+
* Experimental: `@looker/components-theme-editor` package
16+
* Experimental: "Semantic" Layout components - `Layout`, `Header`, `Footer`, `Aside`
1617

1718
### Changed
1819

packages/components/src/Layout/Semantics/Footer.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,10 @@
2525
*/
2626

2727
import styled from 'styled-components'
28-
import { headerFooterCSS } from './Header'
29-
import { SemanticLayoutBase } from './semanticStyledBase'
28+
import { headerFooterCSS, HeaderProps } from './Header'
3029

3130
// eslint-disable-next-line @typescript-eslint/no-empty-interface
32-
export interface FooterProps extends SemanticLayoutBase {}
31+
export interface FooterProps extends HeaderProps {}
3332

3433
export const Footer = styled.footer<FooterProps>`
3534
${headerFooterCSS}

packages/components/src/Layout/Semantics/Layout.tsx

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@
2525
*/
2626

2727
import { CompatibleHTMLProps } from '@looker/design-tokens'
28-
import styled from 'styled-components'
28+
import styled, { css } from 'styled-components'
2929
import { simpleLayoutCSS, SimpleLayoutProps } from '../utils/simple'
30+
import { Section } from './Section'
3031

3132
export interface LayoutProps
3233
extends SimpleLayoutProps,
@@ -38,11 +39,19 @@ export interface LayoutProps
3839
hasAside?: boolean
3940
}
4041

42+
const hasAsideCSS = css`
43+
flex-direction: row;
44+
45+
& > ${Section} {
46+
width: 0;
47+
}
48+
`
49+
4150
export const Layout = styled.div<LayoutProps>`
4251
${simpleLayoutCSS}
4352
4453
display: flex;
45-
flex-direction: ${({ hasAside }) => (hasAside ? 'row' : 'column')};
46-
height: 100%;
47-
width: 100%;
54+
flex: 1 0 auto;
55+
56+
${({ hasAside }) => (hasAside ? hasAsideCSS : 'flex-direction: column;')}
4857
`

packages/components/src/Layout/Semantics/Main.tsx

Lines changed: 0 additions & 35 deletions
This file was deleted.

packages/components/src/Layout/Semantics/Section.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ export interface SectionProps extends SemanticLayoutBase {}
3333
export const sectionCSS = css`
3434
${semanticLayoutCSS}
3535
flex: 1 0 auto;
36-
width: 0;
3736
`
3837

3938
export const Section = styled.section<SectionProps>`

packages/components/src/Layout/Semantics/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,5 @@ export * from './Aside'
2828
export * from './Footer'
2929
export * from './Header'
3030
export * from './Layout'
31-
export * from './Main'
3231
export * from './Page'
3332
export * from './Section'

storybook/src/Layout/ApiExplorer.stories.tsx renamed to storybook/src/Layout/ExamplePage.stories.tsx

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import {
2929
Layout,
3030
Header,
3131
Aside,
32-
Main,
3332
Footer,
3433
Page,
3534
Heading,
@@ -45,20 +44,20 @@ import {
4544
import styled from 'styled-components'
4645

4746
export default {
48-
title: 'Layout',
47+
title: 'Layout/Semantics/ExamplePage',
4948
}
5049

51-
export const ApiExplorer = () => (
50+
export const ExamplePage = () => (
5251
<Highlighter>
53-
<Page supportsScroll={false}>
54-
<Header isFixed height="4rem" px="large">
52+
<Page>
53+
<Header height="4rem" px="large">
5554
Header
5655
</Header>
57-
<Layout>
56+
<Layout hasAside>
5857
<Aside p="large" width="200px">
5958
Aside
6059
</Aside>
61-
<Main p="xxlarge">
60+
<Section p="xxlarge" as="main">
6261
<Heading>Page title</Heading>
6362
<Tabs>
6463
<TabList distribute>
@@ -123,12 +122,14 @@ export const ApiExplorer = () => (
123122
</TabPanel>
124123
</TabPanels>
125124
</Tabs>
126-
</Main>
125+
</Section>
127126
<AsideAlt p="xxlarge" width="25rem">
128127
Alternate Aside
129128
</AsideAlt>
130129
</Layout>
131-
<Footer>Hi to me too!</Footer>
130+
<Footer height="3rem" px="large">
131+
I'm a footer
132+
</Footer>
132133
</Page>
133134
</Highlighter>
134135
)
@@ -150,7 +151,7 @@ const Highlighter = styled.div`
150151
background-color: lightskyblue;
151152
}
152153
153-
${Main}, ${Section} {
154+
${Section} {
154155
background-color: lightgoldenrodyellow;
155156
}
156157
`

storybook/src/Layout/Semantics.stories.tsx

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import {
2929
Layout,
3030
Header,
3131
Aside,
32-
Main,
3332
Footer,
3433
Grid,
3534
Section,
@@ -56,7 +55,7 @@ export const HeaderLayoutAsideMain = () => (
5655
<Header>Header</Header>
5756
<Layout hasAside>
5857
<Aside width="20%">Aside</Aside>
59-
<Main>Main</Main>
58+
<Section>Section</Section>
6059
</Layout>
6160
</Layout>
6261
</Highlighter>
@@ -68,7 +67,7 @@ export const HeaderLayoutAsideMainFooter = () => (
6867
<Header>Header</Header>
6968
<Layout hasAside>
7069
<Aside width="20%">Aside</Aside>
71-
<Main>Main</Main>
70+
<Section>Section</Section>
7271
</Layout>
7372
<Footer>Footer</Footer>
7473
</Layout>
@@ -80,7 +79,7 @@ export const AsideMainFooter = () => (
8079
<Layout>
8180
<Layout hasAside>
8281
<Aside width="20%">Aside</Aside>
83-
<Main>Main</Main>
82+
<Section>Section</Section>
8483
</Layout>
8584
<Footer>Footer</Footer>
8685
</Layout>
@@ -94,7 +93,7 @@ export const AsideLayoutHeaderMainFooter = () => (
9493
<Aside width="20%">Aside</Aside>
9594
<Layout>
9695
<Header>Header</Header>
97-
<Main>Main</Main>
96+
<Section>Section</Section>
9897
<Footer>Footer</Footer>
9998
</Layout>
10099
</Layout>
@@ -111,7 +110,7 @@ export const AsideLayoutHeaderLayoutLayoutMainAsideFooter = () => (
111110
<Header>Header</Header>
112111
<Layout>
113112
<Layout hasAside>
114-
<Main>Main</Main>
113+
<Section>Section</Section>
115114
<Aside width="40%">Aside</Aside>
116115
</Layout>
117116
</Layout>
@@ -127,7 +126,14 @@ const CustomGrid = styled(Grid)`
127126
`
128127

129128
const Highlighter = styled.div`
129+
/* Emulate Page behavior for demos */
130+
height: 100%;
131+
& > ${Layout} {
132+
height: 100%;
133+
}
134+
130135
/* stylelint-disable color-named */
136+
131137
${Header}, ${Footer} {
132138
background-color: lightskyblue;
133139
}
@@ -136,7 +142,7 @@ const Highlighter = styled.div`
136142
background-color: lightsalmon;
137143
}
138144
139-
${Main}, ${Section} {
145+
${Section} {
140146
background-color: lightseagreen;
141147
}
142148
`

0 commit comments

Comments
 (0)