diff --git a/resources/css/components/publish.css b/resources/css/components/publish.css index ef43cf59ad9..8d192521a4f 100644 --- a/resources/css/components/publish.css +++ b/resources/css/components/publish.css @@ -12,7 +12,12 @@ } .form-group { - grid-column: span var(--col-span, var(--grid-columns)); + /* Stacked, until the panel is wide enough for the configured widths to make sense. */ + grid-column: span var(--grid-columns); + + @variant @lg/panel { + grid-column: span var(--col-span, var(--grid-columns)); + } } .spacer-fieldtype { @@ -26,21 +31,15 @@ } } -@variant @lg/panel { - .field-w-25 { --col-span: calc(var(--grid-columns) * 0.25); } - .field-w-33 { --col-span: calc(var(--grid-columns) * 0.333); } - .field-w-50 { --col-span: calc(var(--grid-columns) * 0.5); } - .field-w-66 { --col-span: calc(var(--grid-columns) * 0.666); } - .field-w-75 { --col-span: calc(var(--grid-columns) * 0.75); } - .field-w-undefined, .field-w-100 { --col-span: calc(var(--grid-columns) * 1); } -} - - /* GROUP PUBLISH COMPONENT / FIELD GRID (e.g. BLUEPRINT) =================================================== */ .field-grid { > * { - grid-column: span var(--col-span, var(--grid-columns)); + grid-column: span var(--grid-columns); + + @variant @lg/panel { + grid-column: span var(--col-span, var(--grid-columns)); + } } } diff --git a/resources/css/components/widgets.css b/resources/css/components/widgets.css new file mode 100644 index 00000000000..1705d3b61b6 --- /dev/null +++ b/resources/css/components/widgets.css @@ -0,0 +1,22 @@ +/* GROUP DASHBOARD WIDGETS +=================================================== */ + +.widgets { + display: grid; + --grid-columns: 12; + grid-template-columns: repeat(var(--grid-columns), 1fr); + @apply gap-6; + + > * { + /* + * Stacked, until the dashboard is wide enough for the arrangement to + * hold up. One threshold for every widget, so there are only ever two + * layouts: the one that was configured, or everything in order. + */ + grid-column: span var(--grid-columns); + + @variant @2xl/widgets { + grid-column: span var(--col-span, var(--grid-columns)); + } + } +} diff --git a/resources/css/components/widths.css b/resources/css/components/widths.css new file mode 100644 index 00000000000..e1e579c804b --- /dev/null +++ b/resources/css/components/widths.css @@ -0,0 +1,50 @@ +/* GROUP WIDTHS +=================================================== */ + +/* + * A configured width resolves to a span of a twelve column grid. + * + * Consumed by the publish form grid (publish.css) and the dashboard widget grid + * (widgets.css). Each of those decides for itself at what container width it + * stops honouring the span and stacks everything instead, so these rules are + * unconditional. + * + * Spans and percentages are shared. The size keywords are widgets only, and are + * deliberately not given .field-w- equivalents. + * + * Spans are written as a fraction of --grid-columns rather than as plain numbers + * so that a grid redefining it continues to opt out of column spanning entirely. + * The asset editor does this by setting it to `none`. + */ + +.field-w-1, .widget-w-1 { --col-span: calc(var(--grid-columns) * 1 / 12); } +.field-w-2, .widget-w-2 { --col-span: calc(var(--grid-columns) * 2 / 12); } +.field-w-3, .widget-w-3 { --col-span: calc(var(--grid-columns) * 3 / 12); } +.field-w-4, .widget-w-4 { --col-span: calc(var(--grid-columns) * 4 / 12); } +.field-w-5, .widget-w-5 { --col-span: calc(var(--grid-columns) * 5 / 12); } +.field-w-6, .widget-w-6 { --col-span: calc(var(--grid-columns) * 6 / 12); } +.field-w-7, .widget-w-7 { --col-span: calc(var(--grid-columns) * 7 / 12); } +.field-w-8, .widget-w-8 { --col-span: calc(var(--grid-columns) * 8 / 12); } +.field-w-9, .widget-w-9 { --col-span: calc(var(--grid-columns) * 9 / 12); } +.field-w-10, .widget-w-10 { --col-span: calc(var(--grid-columns) * 10 / 12); } +.field-w-11, .widget-w-11 { --col-span: calc(var(--grid-columns) * 11 / 12); } +.field-w-12, .widget-w-12 { --col-span: calc(var(--grid-columns) * 12 / 12); } + +/* Percentages. The widths available before spans, and still what the width + selector writes. They were always exact twelfths. */ +.field-w-25, .widget-w-25 { --col-span: calc(var(--grid-columns) * 3 / 12); } +.field-w-33, .widget-w-33 { --col-span: calc(var(--grid-columns) * 4 / 12); } +.field-w-50, .widget-w-50 { --col-span: calc(var(--grid-columns) * 6 / 12); } +.field-w-66, .widget-w-66 { --col-span: calc(var(--grid-columns) * 8 / 12); } +.field-w-75, .widget-w-75 { --col-span: calc(var(--grid-columns) * 9 / 12); } +.field-w-100, .widget-w-100 { --col-span: calc(var(--grid-columns) * 12 / 12); } + +/* Size keywords. Widgets only. Fields have never accepted these. */ +.widget-w-sm { --col-span: calc(var(--grid-columns) * 4 / 12); } +.widget-w-md { --col-span: calc(var(--grid-columns) * 6 / 12); } +.widget-w-lg { --col-span: calc(var(--grid-columns) * 9 / 12); } +.widget-w-full { --col-span: calc(var(--grid-columns) * 12 / 12); } + +/* No width configured. Needs a rule of its own rather than relying on the + var() fallback, because --col-span inherits. */ +.field-w-undefined, .widget-w-undefined { --col-span: calc(var(--grid-columns) * 12 / 12); } diff --git a/resources/css/cp.css b/resources/css/cp.css index dd8ab0f1172..16a1d333059 100644 --- a/resources/css/cp.css +++ b/resources/css/cp.css @@ -26,6 +26,8 @@ @import './components/stacks.css'; @import './components/tabs.css'; @import './components/tooltips.css'; +@import './components/widgets.css'; +@import './components/widths.css'; @import './components/wizard.css'; /* Fieldtypes */ diff --git a/resources/js/bootstrap/globals.js b/resources/js/bootstrap/globals.js index 3310ec80d83..0e015762eb9 100644 --- a/resources/js/bootstrap/globals.js +++ b/resources/js/bootstrap/globals.js @@ -49,6 +49,10 @@ export function clone(value) { return JSON.parse(JSON.stringify(value)); } +/** + * @deprecated Widths are resolved by the stylesheet now. Emit `field-w-${width}` + * or `widget-w-${width}` instead. Will be removed in a future major version. + */ export function tailwind_width_class(width) { const widths = { 25: 'w-full @lg:w-1/4', @@ -62,6 +66,11 @@ export function tailwind_width_class(width) { return `${widths[width] || 'w-full'}`; } +/** + * @deprecated Widths are resolved by the stylesheet now, which understands column + * spans as well as these six percentages. Emit `field-w-${width}` instead. + * Will be removed in a future major version. + */ export function field_width_class(width) { const widths = { 25: 'field-w-25', diff --git a/resources/js/components/blueprints/RegularField.vue b/resources/js/components/blueprints/RegularField.vue index fa3e0201fdb..885b0daa636 100644 --- a/resources/js/components/blueprints/RegularField.vue +++ b/resources/js/components/blueprints/RegularField.vue @@ -128,7 +128,7 @@ export default { }, widthClass() { - return `${field_width_class(this.width)}`; + return `field-w-${this.width}`; }, localizable: { diff --git a/resources/js/components/fields/WidthSelector.vue b/resources/js/components/fields/WidthSelector.vue index da07abae1af..2eab1c8d149 100644 --- a/resources/js/components/fields/WidthSelector.vue +++ b/resources/js/components/fields/WidthSelector.vue @@ -1,6 +1,7 @@ @@ -48,10 +25,10 @@ function tailwindWidthClass(width) {