Skip to content
Snippets Groups Projects
Commit fc7c5e98 authored by Rajab Natshah's avatar Rajab Natshah
Browse files

Issue #3381137: Add Auto-docs MDX2 for the Spinner docs page to the Storybook

parent f9bd206b
No related branches found
No related tags found
No related merge requests found
...@@ -2,3 +2,66 @@ ...@@ -2,3 +2,66 @@
Indicate the loading state of a component or page with Bootstrap spinners, built entirely with HTML, CSS, and no JavaScript. Indicate the loading state of a component or page with Bootstrap spinners, built entirely with HTML, CSS, and no JavaScript.
> ### [Bootstrap ~5.3.0 Documentation on Spinners](https://getbootstrap.com/docs/5.3/components/spinners/)
> * [Border spinner](https://getbootstrap.com/docs/5.3/components/spinners/#border-spinner)
> * [Growing spinner](https://getbootstrap.com/docs/5.3/components/spinners/#growing-spinner)
> * [Colors](https://getbootstrap.com/docs/5.3/components/spinners/#colors)
> * [Size](https://getbootstrap.com/docs/5.3/components/spinners/#size)
> * [Hidden Status](https://getbootstrap.com/docs/5.3/components/spinners/#buttons)
### Properties:
* `html_tag`: Having the spinner as div or span.
* `type`: Use the border spinners for a lightweight loading indicator. If you do not fancy a border spinner, switch to the grow spinner. While it does not technically spin, it does repeatedly grow!
* `color`: Built with current Color, so you can easily change its appearance with text color utilities.
(primary|secondary|success|danger|warning|info|dark|light)
* `size`: Make a smaller spinner that can quickly be used within other components.
* `hidden_status`: Hidden spinner status message.
* `utility_classes`: An array of utility classes. Use to add extra Bootstrap utility classes or custom CSS classes over to this component.
### Attributes:
* `attributes`: A list of HTML attributes for the Spinner element.
* `spinner_status_attributes`: A list of HTML attributes for the Spinner status element.
### Slots:
* `content`: Spinner content.
### Examples
**Example #1:** Secondary Spinner
```
{% include 'varbase_components:spinner' with {
color: 'secondary',
content: 'Loading ...'|t,
} %}
```
**Example #2:** Grow Spinner
```
{% include 'varbase_components:spinner' with {
type: 'grow',
content: 'Please, waite ...'|t,
color: 'info',
} %}
```
**Example #3:** Small saving border spinner with status
```
{% include 'varbase_components:spinner' with {
color: 'primary',
type: 'border',
content: 'Saving ...',
size: 'sm',
hidden_status: false
} %}
```
**Example #4:** Small saving grow spinner with status
```
{% include 'varbase_components:spinner' with {
color: 'primary',
type: 'grow',
content: 'Saving ...'|t,
size: 'sm',
hidden_status: false
} %}
```
...@@ -9,6 +9,7 @@ props: ...@@ -9,6 +9,7 @@ props:
type: string type: string
title: HTML tag title: HTML tag
description: Having the spinner as div or span description: Having the spinner as div or span
default: div
enum: enum:
- div - div
- span - span
...@@ -16,36 +17,58 @@ props: ...@@ -16,36 +17,58 @@ props:
type: string type: string
title: Type title: Type
description: Use the border spinners for a lightweight loading indicator. If you do not fancy a border spinner, switch to the grow spinner. While it does not technically spin, it does repeatedly grow! description: Use the border spinners for a lightweight loading indicator. If you do not fancy a border spinner, switch to the grow spinner. While it does not technically spin, it does repeatedly grow!
default: border
enum: enum:
- spinner-border - ''
- spinner-grow - border
- grow
color: color:
type: string type: string
title: Color title: Color
description: Once again, this spinner is built with currentColor, so you can easily change its appearance with text color utilities. Here it is in blue, along with the supported variants. description: Built with current Color, so you can easily change its appearance with text color utilities.
default: ''
enum: enum:
- text-primary - ''
- text-secondary - primary
- text-success - secondary
- text-danger - success
- text-warning - danger
- text-info - warning
- text-dark - info
- text-light - dark
- light
size: size:
type: string type: string
title: Size title: Size
description: Add `.spinner-border-sm` and `.spinner-grow-sm` to make a smaller spinner that can quickly be used within other components. description: Make a smaller spinner that can quickly be used within other components.
default: ''
enum: enum:
- '' - ''
- sm - sm
content: hidden_status:
type: string type: boolean
title: Content title: Hidden status
description: Spinner text description: Hidden spinner status message.
examples: default: true
- Processing utility_classes:
- Saving type: array
- Loading title: Utility Classes
default: []
description: An array of utility classes. Use to add extra Bootstrap utility classes or custom CSS classes over to this component.
attributes: attributes:
type: Drupal\Core\Template\Attribute type: Drupal\Core\Template\Attribute
title: Attributes
description: A list of HTML attributes for the Spinner element.
spinner_status_attributes:
type: Drupal\Core\Template\Attribute
title: Spinner Status Attributes
description: A list of HTML attributes for the Spinner status element.
slots:
content:
type: string
title: Content
description: Spinner content
examples:
- Processing
- Saving
- Loading
{/* Spinner.mdx */}
import { Canvas, Title, Subtitle, ArgTypes, Source, Meta, Description, Primary, Story, Stories, Controls } from '@storybook/blocks';
import * as comStories from './spinner.stories.json';
import templateSource from './spinner.twig?raw';
<Meta of={comStories} name="Docs"/>
<Title />
<Subtitle />
<Description />
> ### [Bootstrap ~5.3.0 Documentation on Spinners](https://getbootstrap.com/docs/5.3/components/spinners/)
> * [Border spinner](https://getbootstrap.com/docs/5.3/components/spinners/#border-spinner)
> * [Growing spinner](https://getbootstrap.com/docs/5.3/components/spinners/#growing-spinner)
> * [Colors](https://getbootstrap.com/docs/5.3/components/spinners/#colors)
> * [Size](https://getbootstrap.com/docs/5.3/components/spinners/#size)
> * [Hidden Status](https://getbootstrap.com/docs/5.3/components/spinners/#buttons)
<Canvas of={comStories.Spinner} />
## Properties
<Controls of={comStories.Spinner} />
<Stories of={comStories} />
## Attributes:
* `attributes`: A list of HTML attributes for the Spinner element.
* `spinner_status_attributes`: A list of HTML attributes for the Spinner status element.
## Slots:
* `content`: Spinner content.
### Examples
**Example #1:** Secondary Spinner
```
{% include 'varbase_components:spinner' with {
color: 'secondary',
content: 'Loading ...'|t,
} %}
```
**Example #2:** Grow Spinner
```
{% include 'varbase_components:spinner' with {
type: 'grow',
content: 'Please, waite ...'|t,
color: 'info',
} %}
```
**Example #3:** Small saving border spinner with status
```
{% include 'varbase_components:spinner' with {
color: 'primary',
type: 'border',
content: 'Saving ...',
size: 'sm',
hidden_status: false
} %}
```
**Example #4:** Small saving grow spinner with status
```
{% include 'varbase_components:spinner' with {
color: 'primary',
type: 'grow',
content: 'Saving ...'|t,
size: 'sm',
hidden_status: false
} %}
```
## Source code
[//]: # (Twig Template source code)
<Source code={templateSource} />
{
"title": "Varbase Components/Atoms/Spinner",
"tags": [
"autodocs"
],
"parameters": {
"componentSubtitle": "Bootstrap Spinner Component",
"docs": {
"description": {
"component": "Indicate the loading state of a component or page with Bootstrap spinners, built entirely with HTML, CSS, and no JavaScript."
},
"story": {
"inline": true
}
}
},
"argTypes": {
"html_tag": {
"name": "HTML tag",
"description": "Having the spinner as div or span",
"defaultValue": "div",
"control": "select",
"options": {
"div": "div",
"span": "span"
}
},
"type": {
"name": "Type",
"description": "Use the border spinners for a lightweight loading indicator. If you do not fancy a border spinner, switch to the grow spinner. While it does not technically spin, it does repeatedly grow!",
"defaultValue": "border",
"control": "select",
"options": {
"'- none -'": "",
"Border": "border",
"Grow": "grow"
}
},
"color": {
"name": "Color",
"description": "Built with current Color, so you can easily change its appearance with text color utilities.",
"defaultValue": "",
"control": "select",
"options": {
"'- none -'": "",
"Primary": "primary",
"Secondary": "secondary",
"Success": "success",
"Danger": "danger",
"Warning": "warning",
"Info": "info",
"Light": "light",
"Dark": "dark"
}
},
"size": {
"name": "Size",
"description": "Make a smaller spinner that can quickly be used within other components.",
"defaultValue": "",
"control": "select",
"options": {
"'- none -'": "",
"Small": "sm"
}
},
"hidden_status": {
"name": "Hidden status",
"description": "Hidden spinner status message.",
"defaultValue": true,
"control": "boolean"
},
"content": {
"name": "Content",
"description": "Spinner text",
"defaultValue": "",
"control": "text"
}
},
"stories": [
{
"name": "Spinner",
"args": {
"html_tag": "div",
"type": "border",
"color": "",
"size": "",
"hidden_status": true,
"content": "Processing ..."
}
},
{
"name": "Grow",
"args": {
"html_tag": "div",
"type": "grow",
"color": "",
"size": "",
"hidden_status": true,
"content": "Loading ..."
}
},
{
"name": "Border - small",
"args": {
"html_tag": "div",
"type": "border",
"color": "",
"size": "sm",
"hidden_status": false,
"content": "Saving ..."
}
},
{
"name": "Grow - small",
"args": {
"html_tag": "div",
"type": "grow",
"color": "",
"size": "sm",
"hidden_status": false,
"content": "Saving ..."
}
},
{
"name": "Primary",
"args": {
"html_tag": "div",
"type": "border",
"color": "primary",
"size": "",
"hidden_status": true,
"content": "Loading ..."
}
},
{
"name": "Secondary",
"args": {
"html_tag": "div",
"type": "border",
"color": "secondary",
"size": "",
"hidden_status": true,
"content": "Loading ..."
}
},
{
"name": "Success",
"args": {
"html_tag": "div",
"type": "border",
"color": "success",
"size": "",
"hidden_status": true,
"content": "Loading ..."
}
},
{
"name": "Danger",
"args": {
"html_tag": "div",
"type": "border",
"color": "danger",
"size": "",
"hidden_status": true,
"content": "Loading ..."
}
},
{
"name": "Warning",
"args": {
"html_tag": "div",
"type": "border",
"color": "warning",
"size": "",
"hidden_status": true,
"content": "Loading ..."
}
},
{
"name": "Info",
"args": {
"html_tag": "div",
"type": "border",
"color": "info",
"size": "",
"hidden_status": true,
"content": "Loading ..."
}
},
{
"name": "Dark",
"args": {
"html_tag": "div",
"type": "border",
"color": "dark",
"size": "",
"hidden_status": true,
"content": "Loading ..."
}
},
{
"name": "Light",
"args": {
"html_tag": "div",
"type": "border",
"color": "light",
"size": "",
"hidden_status": true,
"content": "Loading ..."
}
}
]
}
...@@ -3,26 +3,61 @@ ...@@ -3,26 +3,61 @@
* @file * @file
* Varbase Components implementation for a Spinner component. * Varbase Components implementation for a Spinner component.
* *
* Available config: * Available properties:
* - tag: div | span * - html_tag: Having the spinner as div or span.
* - type: spinner-border | spinner-grow * - type: Use the border spinners for a lightweight loading indicator. If you do not fancy a border spinner, switch to the grow spinner. While it does not technically spin, it does repeatedly grow!
* - color: text-primary | text-secondary | text-success | text-danger | text-warning | text-info | text-dark | text-light * - color: Built with current Color, so you can easily change its appearance with text color utilities.
* - size: sm * (primary|secondary|success|danger|warning|info|dark|light)
* - attributes: Attributes array. * - size: Make a smaller spinner that can quickly be used within other components.
* - utility_classes: An array of utility classes. * - hidden_status: Hidden spinner status message.
* - utility_classes: An array of utility classes. Use to add extra Bootstrap utility classes or custom CSS classes over to this component.
*
* Available attributes:
* - attributes: A list of HTML attributes for the Spinner element.
* - spinner_status_attributes: A list of HTML attributes for the Spinner status element.
*
* Available slots:
* - content: Spinner content.
* **Examples:**
* - Processing
* - Saving
* - Loading
*
*/ */
#} #}
{% set html_tag = html_tag ? html_tag : 'div' %}
{% set type = type ?? 'border' %}
{% set type_classes = type ? ['spinner-' ~ type] : ['spinner-border'] %}
{% set size_classes = size ? ['spinner-' ~ type ~ '-' ~ size] : [] %}
{% set color_classes = color ? ['text-' ~ color] : [] %}
{% set hidden_status = hidden_status ?? true %}
{% set utility_classes = utility_classes ? utility_classes : [] %} {% set utility_classes = utility_classes ? utility_classes : [] %}
{% set classes = [ {% set classes = []|merge(type_classes)|merge(size_classes)|merge(color_classes)|merge(utility_classes) %}
type ? type : 'spinner-border',
color ? color : '', {% if not attributes %}
size ? type ~ '-' ~ size : '', {% set attributes = create_attribute() %}
]|merge(utility_classes) %} {% endif %}
{% set attributes = attributes.addClass(classes) %}
{% if not spinner_status_attributes %}
{% set spinner_status_attributes = create_attribute() %}
{% endif %}
{% if hidden_status %}
{% set attributes = attributes.setAttribute('role', 'status') %}
{% set attributes = attributes.setAttribute('aria-hidden', 'true') %}
{% set spinner_status_attributes = spinner_status_attributes.addClass('visually-hidden') %}
{% else %}
{% set spinner_status_attributes = spinner_status_attributes.setAttribute('role', 'status') %}
{% endif %}
<{{ tag }} {{ attributes.addClass(classes) }} role="status"> <{{ html_tag }}{{ attributes }}>{% apply spaceless %}
{% if content %} {% if content and hidden_status %}
<span class="visually-hidden">{{ content }}</span> <span{{ spinner_status_attributes }}>{{ content }}</span>
{% endif %} {% endif %}
</{{ tag }}> {% endapply %}</{{ html_tag }}>
{% if content and not hidden_status %}{% apply spaceless %}
<span{{ spinner_status_attributes }}>{{ content }}</span>
{% endapply %}{% endif %}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment