|
|
--- |
|
|
interface Props { |
|
|
|
|
|
layout?: "2-column" | "3-column" | "4-column" | "auto"; |
|
|
|
|
|
gap?: "small" | "medium" | "large" | string; |
|
|
|
|
|
class?: string; |
|
|
|
|
|
id?: string; |
|
|
} |
|
|
|
|
|
const { |
|
|
layout = "2-column", |
|
|
gap = "medium", |
|
|
class: className, |
|
|
id, |
|
|
} = Astro.props as Props; |
|
|
|
|
|
|
|
|
const getFlexProperties = () => { |
|
|
switch (layout) { |
|
|
case "2-column": |
|
|
return { flexBasis: "50%", maxWidth: "50%" }; |
|
|
case "3-column": |
|
|
return { flexBasis: "33.333%", maxWidth: "33.333%" }; |
|
|
case "4-column": |
|
|
return { flexBasis: "25%", maxWidth: "25%" }; |
|
|
case "auto": |
|
|
return { flexBasis: "auto", maxWidth: "none" }; |
|
|
default: |
|
|
|
|
|
return { flexBasis: "auto", maxWidth: "none" }; |
|
|
} |
|
|
}; |
|
|
|
|
|
const getGapSize = () => { |
|
|
|
|
|
switch (gap) { |
|
|
case "small": |
|
|
return "0.5rem"; |
|
|
case "medium": |
|
|
return "1rem"; |
|
|
case "large": |
|
|
return "1.5rem"; |
|
|
default: |
|
|
|
|
|
return gap; |
|
|
} |
|
|
}; |
|
|
|
|
|
const flexProps = getFlexProperties(); |
|
|
const gapSize = getGapSize(); |
|
|
--- |
|
|
|
|
|
<div |
|
|
class={`stack ${className || ""}`} |
|
|
data-layout={layout} |
|
|
data-gap={gap} |
|
|
{id} |
|
|
style={`gap: ${gapSize}`} |
|
|
> |
|
|
<slot /> |
|
|
</div> |
|
|
|
|
|
<style> |
|
|
.stack { |
|
|
display: grid; |
|
|
gap: 1rem; |
|
|
margin: var(--block-spacing-y) 0; |
|
|
width: 100%; |
|
|
max-width: 100%; |
|
|
box-sizing: border-box; |
|
|
} |
|
|
|
|
|
|
|
|
.stack[data-layout="2-column"] { |
|
|
grid-template-columns: repeat(2, 1fr); |
|
|
} |
|
|
|
|
|
.stack[data-layout="3-column"] { |
|
|
grid-template-columns: repeat(3, 1fr); |
|
|
} |
|
|
|
|
|
.stack[data-layout="4-column"] { |
|
|
grid-template-columns: repeat(4, 1fr); |
|
|
} |
|
|
|
|
|
.stack[data-layout="auto"] { |
|
|
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); |
|
|
} |
|
|
|
|
|
|
|
|
.stack:not([data-layout]) { |
|
|
grid-template-columns: repeat(2, 1fr); |
|
|
} |
|
|
|
|
|
|
|
|
.stack :global(> *) { |
|
|
min-width: 0 !important; |
|
|
max-width: 100% !important; |
|
|
box-sizing: border-box !important; |
|
|
word-wrap: break-word !important; |
|
|
overflow-wrap: break-word !important; |
|
|
overflow: hidden !important; |
|
|
} |
|
|
|
|
|
|
|
|
.stack pre { |
|
|
overflow-x: auto; |
|
|
max-width: 100%; |
|
|
width: 100%; |
|
|
word-wrap: break-word; |
|
|
white-space: pre-wrap; |
|
|
box-sizing: border-box; |
|
|
min-width: 0 !important; |
|
|
} |
|
|
|
|
|
.stack code { |
|
|
word-wrap: break-word; |
|
|
white-space: pre-wrap; |
|
|
max-width: 100%; |
|
|
box-sizing: border-box; |
|
|
min-width: 0 !important; |
|
|
} |
|
|
|
|
|
|
|
|
.stack pre code { |
|
|
min-width: 0 !important; |
|
|
} |
|
|
|
|
|
|
|
|
.stack section.content-grid pre code { |
|
|
min-width: 0 !important; |
|
|
} |
|
|
|
|
|
|
|
|
@media (max-width: 768px) { |
|
|
.stack[data-layout="3-column"], |
|
|
.stack[data-layout="4-column"], |
|
|
.stack[data-layout="2-column"], |
|
|
.stack:not([data-layout]) { |
|
|
grid-template-columns: 1fr !important; |
|
|
} |
|
|
} |
|
|
|
|
|
@media (min-width: 769px) and (max-width: 1100px) { |
|
|
.stack[data-layout="3-column"], |
|
|
.stack[data-layout="4-column"] { |
|
|
grid-template-columns: repeat(2, 1fr) !important; |
|
|
} |
|
|
} |
|
|
|
|
|
@media (min-width: 1101px) and (max-width: 1400px) { |
|
|
.stack[data-layout="4-column"] { |
|
|
grid-template-columns: repeat(2, 1fr) !important; |
|
|
} |
|
|
} |
|
|
</style> |
|
|
|