From d26cd3a7dff6c343939892ccf3e6eec533c9e591 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Kry=C5=A1p=C3=ADn?= Date: Sun, 2 Apr 2023 14:22:35 +0200 Subject: [PATCH] Feat(web-twig): Introduce GridSpan --- .../Resources/components/Grid/GridSpan.twig | 23 ++++++++ .../src/Resources/components/Grid/README.md | 57 ++++++++++++++++++- .../Resources/twig-components/gridSpan.twig | 1 + 3 files changed, 79 insertions(+), 2 deletions(-) create mode 100644 packages/web-twig/src/Resources/components/Grid/GridSpan.twig create mode 100644 packages/web-twig/src/Resources/twig-components/gridSpan.twig diff --git a/packages/web-twig/src/Resources/components/Grid/GridSpan.twig b/packages/web-twig/src/Resources/components/Grid/GridSpan.twig new file mode 100644 index 0000000000..0080fd0081 --- /dev/null +++ b/packages/web-twig/src/Resources/components/Grid/GridSpan.twig @@ -0,0 +1,23 @@ +{# API #} +{%- set props = props | default([]) -%} +{%- set _class = props.class | default(null) -%} +{%- set _over = props.over | default(null) -%} +{%- set _desktop = props.desktop | default(null) -%} +{%- set _elementType = props.elementType | default('div') -%} +{%- set _tablet = props.tablet | default(null) -%} + +{# Class names #} +{%- set _overClassName = _over ? _spiritClassPrefix ~ 'Grid__span--over-' ~ _over : null -%} +{%- set _desktopClassName = _desktop ? _spiritClassPrefix ~ 'Grid__span--desktop--over-' ~ _desktop : null -%} +{%- set _tabletClassName = _tablet ? _spiritClassPrefix ~ 'Grid__span--tablet--over-' ~ _tablet : null -%} +{%- set _rootClassName = _spiritClassPrefix ~ 'Grid__span' -%} + +{# Miscellaneous #} +{%- set _classNames = [ _rootClassName, _overClassName, _tabletClassName, _desktopClassName, _class ] -%} + +<{{ _elementType }} + {{ mainProps(props) }} + {{ classProp(_classNames) }} +> + {%- block content %}{% endblock -%} + diff --git a/packages/web-twig/src/Resources/components/Grid/README.md b/packages/web-twig/src/Resources/components/Grid/README.md index f938d7d9c8..be75b11371 100644 --- a/packages/web-twig/src/Resources/components/Grid/README.md +++ b/packages/web-twig/src/Resources/components/Grid/README.md @@ -2,6 +2,8 @@ This is Twig implementation of the [Grid] component. +## Grid + Basic example usage: ```html @@ -47,17 +49,68 @@ Without lexer: {% endembed %} ``` -## API +### API | Prop name | Type | Default | Required | Description | | ------------- | ---------------------------------- | ------- | -------- | ----------------------------------- | | `cols` | `1`, `2`, `3`, `4`, `5`, `6`, `12` | `null` | no | Number of columns to use | -| `desktop` | `1`, `2`, `3`, `4`, `5`, `6`, `12` | `null` | no | Number of columns to use on desktop | | `tablet` | `1`, `2`, `3`, `4`, `5`, `6`, `12` | `null` | no | Number of columns to use on tablet | +| `desktop` | `1`, `2`, `3`, `4`, `5`, `6`, `12` | `null` | no | Number of columns to use on desktop | | `class` | `string` | `null` | no | Custom CSS class | | `elementType` | `string` | `div` | no | HTML tag to render | You can add `id`, `data-*` or `aria-*` attributes to further extend component's descriptiveness and accessibility. +## GridSpan + +Grid Span allows to center content over multiple grid columns. + +For more info when and why to use it, see [Grid] component. + +Basic example usage: + +```html + + 2 + 4 + 6 + 8 + 10 + +``` + +Advanced example usage: + +```html + + 10 on mobile, 8 on tablet, 6 on desktop + +``` + +Without lexer: + +```twig +{% embed "@spirit/gridSpan.twig" with { props: { + over: 2, +}} %} + {% block content %} + over 2 + {% endblock %} +{% endembed %} +``` + +### API + +| Prop name | Type | Default | Required | Description | +| ------------- | ------------------------------ | ------- | -------- | ----------------------------------------- | +| `over` | `2`, `4`, `6`, `8`, `10`, `12` | `null` | no | Number of columns to span over | +| `tablet` | `2`, `4`, `6`, `8`, `10`, `12` | `null` | no | Number of columns to span over on tablet | +| `desktop` | `2`, `4`, `6`, `8`, `10`, `12` | `null` | no | Number of columns to span over on desktop | +| `class` | `string` | `null` | no | Custom CSS class | +| `elementType` | `string` | `div` | no | HTML tag to render | + +You can add `id`, `data-*` or `aria-*` attributes to further extend component's +descriptiveness and accessibility. + [grid]: https://github.com/lmc-eu/spirit-design-system/tree/main/packages/web/src/scss/components/Grid diff --git a/packages/web-twig/src/Resources/twig-components/gridSpan.twig b/packages/web-twig/src/Resources/twig-components/gridSpan.twig new file mode 100644 index 0000000000..0991cd43b7 --- /dev/null +++ b/packages/web-twig/src/Resources/twig-components/gridSpan.twig @@ -0,0 +1 @@ +{% extends '@spirit/Grid/GridSpan.twig' %}