Skip to content

Commit 5db4772

Browse files
committed
feat: column layout ui and responsiveness
1 parent e1f72d7 commit 5db4772

14 files changed

+62
-52
lines changed

.vscode/settings.json

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{
2+
"css.validate": false,
23
"eslint.validate": ["typescript", "astro"]
34
}

packages/astro-content-devtools/src/components/Devtools.tsx

+2-16
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { Toggle } from './Toggle'
1212

1313
export const Devtools: Component = () => {
1414
const { collections, isOverlayOpened } = useDevtools()
15-
const { collectionName, entrySlug, previewType } = useSelection()
15+
const { collectionName, previewType } = useSelection()
1616

1717
const shouldShowPreviewTypesPanel = () => {
1818
const activeCollectionName = collectionName()
@@ -31,24 +31,10 @@ export const Devtools: Component = () => {
3131
}
3232
const shouldShowSchemaPanel = () => shouldShowPreviewTypesPanel() && previewType() === 'schema'
3333
const shouldShowEntriesPanel = () => shouldShowPreviewTypesPanel() && previewType() === 'data'
34-
const shouldShowDataPanel = () =>
35-
shouldShowPreviewTypesPanel() && previewType() === 'data' && entrySlug() !== undefined
36-
37-
const columnCount = () => {
38-
if (!shouldShowPreviewTypesPanel()) {
39-
return 1
40-
}
41-
42-
if (!shouldShowSchemaPanel() && !shouldShowEntriesPanel()) {
43-
return 2
44-
}
45-
46-
return shouldShowDataPanel() ? 4 : 3
47-
}
4834

4935
return (
5036
<aside>
51-
<Panels columns={columnCount()}>
37+
<Panels>
5238
<CollectionsPanel />
5339
<Show when={shouldShowPreviewTypesPanel()}>
5440
<PreviewTypesPanel />

packages/astro-content-devtools/src/components/data/DataFrontmatter.tsx

+4-2
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@ import { type FrontmatterProperty, getFrontmatterProperties } from '../../libs/f
55
import styles from './DataFrontmatter.module.css'
66

77
export const DataFrontmatter: Component<DataFrontmatterProps> = (props) => {
8-
const properties = getFrontmatterProperties(props.frontmatter)
8+
const properties = () => getFrontmatterProperties(props.frontmatter)
99

1010
return (
1111
<ul class={styles.properties}>
12-
<For each={properties}>{(property) => <DataFrontmatterProperty key={property.key} value={property.value} />}</For>
12+
<For each={properties()}>
13+
{(property) => <DataFrontmatterProperty key={property.key} value={property.value} />}
14+
</For>
1315
</ul>
1416
)
1517
}

packages/astro-content-devtools/src/components/panels/CollectionsPanel.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export const CollectionsPanel: Component = () => {
1717
const collectionNames = Object.keys(collections)
1818

1919
return (
20-
<Panel>
20+
<Panel name="collections">
2121
<Toggle />
2222
<ul>
2323
<For each={collectionNames}>

packages/astro-content-devtools/src/components/panels/DataPanel.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export const DataPanel: Component = () => {
2727
const [entry] = createResource(collectionNameAndEntrySlyg, fetchCollectionEntry)
2828

2929
return (
30-
<Panel style={{ 'background-color': 'var(--acd-color-gray-700)' }}>
30+
<Panel name="data" style={{ 'background-color': 'var(--acd-color-gray-700)' }}>
3131
<Show when={entry() !== undefined} fallback="// TODO(HiDeoo) pelase select a valid entry">
3232
<DataSection title="Details">
3333
<DataVariable key="ID" value={entry()?.id} />

packages/astro-content-devtools/src/components/panels/EntriesPanel.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export const EntriesPanel: Component = () => {
1515

1616
return (
1717
<>
18-
<Panel>
18+
<Panel name="entries">
1919
<ul>
2020
<For each={entries()}>
2121
{(panelEntry: CollectionEntry) => {

packages/astro-content-devtools/src/components/panels/Panel.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ import styles from './Panel.module.css'
44

55
export const Panel: ParentComponent<PanelProps> = (props) => {
66
return (
7-
<div class={styles.panel} style={props.style}>
7+
<div class={styles.panel} classList={{ [`acd-panel-${props.name}`]: true }} style={props.style}>
88
{props.children}
99
</div>
1010
)
1111
}
1212

1313
interface PanelProps {
14+
name: string
1415
style?: JSX.CSSProperties | string
1516
}

packages/astro-content-devtools/src/components/panels/Panels.module.css

+41-7
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,52 @@
2121
pointer-events: all;
2222
}
2323

24-
.column1 {
24+
.devtools:has(> :last-child:nth-child(1)) {
2525
grid-template-columns: 1fr;
2626
}
2727

28-
.column2 {
29-
grid-template-columns: 1fr 1fr;
28+
.devtools:has(> :last-child:nth-child(2)) {
29+
grid-template-columns: repeat(2, 1fr);
30+
grid-template-rows: 1fr;
3031
}
3132

32-
.columns3 {
33-
grid-template-columns: 20% 20% 1fr;
33+
.devtools:has(> :last-child:nth-child(3):not(:global(.acd-panel-entries))) {
34+
grid-template-columns: repeat(2, 1fr);
35+
grid-template-rows: auto 1fr;
36+
37+
& > div:nth-child(3) {
38+
grid-column: 1 / span 2;
39+
}
40+
41+
@media (min-width: 800px) {
42+
grid-template-columns: var(--acd-panel-width) var(--acd-panel-width) 1fr;
43+
grid-template-rows: 1fr;
44+
45+
& > div:nth-child(3) {
46+
grid-column: 3;
47+
}
48+
}
49+
}
50+
51+
.devtools:has(> :last-child:nth-child(3):global(.acd-panel-entries)) {
52+
grid-template-columns: repeat(3, 1fr);
53+
grid-template-rows: 1fr;
3454
}
3555

36-
.columns4 {
37-
grid-template-columns: 20% 20% 20% 1fr;
56+
.devtools:has(> :last-child:nth-child(4)) {
57+
grid-template-columns: repeat(3, 1fr);
58+
grid-template-rows: auto 1fr;
59+
60+
& > div:nth-child(4) {
61+
grid-column: 1 / span 3;
62+
}
63+
64+
@media (min-width: 800px) {
65+
grid-template-columns: var(--acd-panel-width) var(--acd-panel-width) var(--acd-panel-width) 1fr;
66+
grid-template-rows: 1fr;
67+
68+
& > div:nth-child(4) {
69+
grid-column: 4;
70+
}
71+
}
3872
}

packages/astro-content-devtools/src/components/panels/Panels.tsx

+2-15
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,12 @@ import { ErrorBoundary } from '../ErrorBoundary'
55

66
import styles from './Panels.module.css'
77

8-
export const Panels: ParentComponent<PanelsProps> = (props) => {
8+
export const Panels: ParentComponent = (props) => {
99
const { isOverlayOpened } = useDevtools()
1010

1111
return (
12-
<div
13-
class={styles.devtools}
14-
classList={{
15-
[styles.opened!]: isOverlayOpened(),
16-
[styles.column1!]: props.columns === 1,
17-
[styles.column2!]: props.columns === 2,
18-
[styles.columns3!]: props.columns === 3,
19-
[styles.columns4!]: props.columns === 4,
20-
}}
21-
>
12+
<div class={styles.devtools} classList={{ [styles.opened!]: isOverlayOpened() }}>
2213
<ErrorBoundary>{props.children}</ErrorBoundary>
2314
</div>
2415
)
2516
}
26-
27-
interface PanelsProps {
28-
columns: 1 | 2 | 3 | 4
29-
}

packages/astro-content-devtools/src/components/panels/PreviewTypesPanel.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export const PreviewTypesPanel: Component = () => {
1111
const { previewType, setPreviewType } = useSelection()
1212

1313
return (
14-
<Panel>
14+
<Panel name="previewType">
1515
<ul>
1616
<For each={PREVIEW_TYPES}>
1717
{(panelPreviewType: PreviewType) => {

packages/astro-content-devtools/src/components/panels/SchemaPanel.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export const SchemaPanel: Component = () => {
2727
}
2828

2929
return (
30-
<Panel>
30+
<Panel name="schema">
3131
<Schema root schema={schema()} />
3232
</Panel>
3333
)
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
.type {
2-
align-items: center;
2+
align-items: flex-start;
33
display: flex;
4-
min-width: 0;
54
}
65

76
.details {
87
display: block;
98
font-size: var(--acd-text-sm);
9+
margin-top: 1px;
1010
margin-left: var(--acd-size-1-5);
11-
overflow: hidden;
12-
text-overflow: ellipsis;
13-
white-space: nowrap;
1411
}

packages/astro-content-devtools/src/components/schemas/TabularSchema.module.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
.propertyName {
5959
color: var(--acd-color-white);
6060
font-weight: var(--acd-font-medium);
61-
white-space: pre;
61+
white-space: nowrap;
6262
}
6363

6464
.object > .propertyName:not(.required) {

packages/astro-content-devtools/src/styles/theme.css

+2
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,6 @@
3232
--acd-size-5: 1.25rem;
3333

3434
--acd-duration-150: 150ms;
35+
36+
--acd-panel-width: min(17rem, 15%);
3537
}

0 commit comments

Comments
 (0)