Skip to content

Commit

Permalink
Fix StackBlitz Popovers and Tooltips examples
Browse files Browse the repository at this point in the history
  • Loading branch information
julien-deramond authored and GeoSot committed May 31, 2022
1 parent d388bd6 commit 5ac36b6
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 21 deletions.
2 changes: 1 addition & 1 deletion site/content/docs/5.2/components/alerts.md
Expand Up @@ -27,7 +27,7 @@ Alerts are available for any length of text, as well as an optional close button

Click the button below to show an alert (hidden with inline styles to start), then dismiss (and destroy) it with the built-in close button.

{{< example js_snippet="true" >}}
{{< example sb_js_snippet="true" >}}
<div id="liveAlertPlaceholder"></div>
<button type="button" class="btn btn-primary" id="liveAlertBtn">Show live alert</button>
{{< /example >}}
Expand Down
2 changes: 1 addition & 1 deletion site/content/docs/5.2/components/modal.md
Expand Up @@ -444,7 +444,7 @@ Have a bunch of buttons that all trigger the same modal with slightly different

Below is a live demo followed by example HTML and JavaScript. For more information, [read the modal events docs](#events) for details on `relatedTarget`.

{{< example js_snippet="true" >}}
{{< example sb_js_snippet="true" >}}
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#exampleModal" data-bs-whatever="@mdo">Open modal for @mdo</button>
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#exampleModal" data-bs-whatever="@fat">Open modal for @fat</button>
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#exampleModal" data-bs-whatever="@getbootstrap">Open modal for @getbootstrap</button>
Expand Down
14 changes: 7 additions & 7 deletions site/content/docs/5.2/components/popovers.md
Expand Up @@ -46,15 +46,15 @@ const popoverList = [...popoverTriggerList].map(popoverTriggerEl => new bootstra

We use JavaScript similar to the snippet above to render the following live popover. Titles are set via `title` attribute and body content is set via `data-bs-content`.

{{< example js_snippet="true" >}}
{{< example sb_hide="true" sb_js_snippet="true" >}}
<button type="button" class="btn btn-lg btn-danger" data-bs-toggle="popover" title="Popover title" data-bs-content="And here's some amazing content. It's very engaging. Right?">Click to toggle popover</button>
{{< /example >}}

### Four directions

Four options are available: top, right, bottom, and left. Directions are mirrored when using Bootstrap in RTL. Set `data-bs-placement` to change the direction.

{{< example js_snippet="true" >}}
{{< example sb_js_snippet="true" >}}
<button type="button" class="btn btn-secondary" data-bs-container="body" data-bs-toggle="popover" data-bs-placement="top" data-bs-content="Top popover">
Popover on top
</button>
Expand Down Expand Up @@ -87,11 +87,11 @@ You can customize the appearance of popovers using [CSS variables](#variables).

{{< scss-docs name="custom-popovers" file="site/assets/scss/_component-examples.scss" >}}

{{< example class="custom-popover-demo" js_snippet="true" >}}
{{< example class="custom-popover-demo" sb_js_snippet="true" >}}
<button type="button" class="btn btn-secondary"
data-bs-toggle="popover" data-bs-placement="right"
data-bs-custom-class="custom-popover"
title="Custom popover"
data-bs-title="Custom popover"
data-bs-content="This popover is themed via CSS variables.">
Custom popover
</button>
Expand All @@ -107,8 +107,8 @@ Use the `focus` trigger to dismiss popovers on the user's next click of a differ
For proper cross-browser and cross-platform behavior, you must use the `<a>` tag, _not_ the `<button>` tag, and you also must include a [`tabindex`](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/tabindex) attribute.
{{< /callout >}}

{{< example js_snippet="true" >}}
<a tabindex="0" class="btn btn-lg btn-danger" role="button" data-bs-toggle="popover" data-bs-trigger="focus" title="Dismissible popover" data-bs-content="And here's some amazing content. It's very engaging. Right?">Dismissible popover</a>
{{< example sb_js_snippet="true" >}}
<a tabindex="0" class="btn btn-lg btn-danger" role="button" data-bs-toggle="popover" data-bs-trigger="focus" data-bs-title="Dismissible popover" data-bs-content="And here's some amazing content. It's very engaging. Right?">Dismissible popover</a>
{{< /example >}}

```js
Expand All @@ -123,7 +123,7 @@ Elements with the `disabled` attribute aren't interactive, meaning users cannot

For disabled popover triggers, you may also prefer `data-bs-trigger="hover focus"` so that the popover appears as immediate visual feedback to your users as they may not expect to _click_ on a disabled element.

{{< example js_snippet="true" >}}
{{< example sb_js_snippet="true" >}}
<span class="d-inline-block" tabindex="0" data-bs-toggle="popover" data-bs-trigger="hover focus" data-bs-content="Disabled popover">
<button class="btn btn-primary" type="button" disabled>Disabled button</button>
</span>
Expand Down
2 changes: 1 addition & 1 deletion site/content/docs/5.2/components/toasts.md
Expand Up @@ -197,7 +197,7 @@ Building on the above example, you can create different toast color schemes with

Place toasts with custom CSS as you need them. The top right is often used for notifications, as is the top middle. If you're only ever going to show one toast at a time, put the positioning styles right on the `.toast`.

{{< example js_snippet="true" >}}
{{< example sb_js_snippet="true" >}}
<form>
<div class="mb-3">
<label for="selectToastPlacement">Toast placement</label>
Expand Down
8 changes: 4 additions & 4 deletions site/content/docs/5.2/components/tooltips.md
Expand Up @@ -45,8 +45,8 @@ const tooltipList = [...tooltipTriggerList].map(tooltipTriggerEl => new bootstra

Hover over the links below to see tooltips:

{{< example class="tooltip-demo" js_snippet="true" >}}
<p class="muted">Placeholder text to demonstrate some <a href="#" data-bs-toggle="tooltip" title="Default tooltip">inline links</a> with tooltips. This is now just filler, no killer. Content placed here just to mimic the presence of <a href="#" data-bs-toggle="tooltip" title="Another tooltip">real text</a>. And all that just to give you an idea of how tooltips would look when used in real-world situations. So hopefully you've now seen how <a href="#" data-bs-toggle="tooltip" title="Another one here too">these tooltips on links</a> can work in practice, once you use them on <a href="#" data-bs-toggle="tooltip" title="The last tip!">your own</a> site or project.
{{< example class="tooltip-demo" sb_js_snippet="true" >}}
<p class="muted">Placeholder text to demonstrate some <a href="#" data-bs-toggle="tooltip" data-bs-title="Default tooltip">inline links</a> with tooltips. This is now just filler, no killer. Content placed here just to mimic the presence of <a href="#" data-bs-toggle="tooltip" data-bs-title="Another tooltip">real text</a>. And all that just to give you an idea of how tooltips would look when used in real-world situations. So hopefully you've now seen how <a href="#" data-bs-toggle="tooltip" data-bs-title="Another one here too">these tooltips on links</a> can work in practice, once you use them on <a href="#" data-bs-toggle="tooltip" data-bs-title="The last tip!">your own</a> site or project.
</p>
{{< /example >}}

Expand All @@ -59,11 +59,11 @@ You can customize the appearance of tooltips using [CSS variables](#variables).
{{< scss-docs name="custom-tooltip" file="site/assets/scss/_component-examples.scss" >}}


{{< example class="tooltip-demo" js_snippet="true" >}}
{{< example class="tooltip-demo" sb_js_snippet="true" >}}
<button type="button" class="btn btn-secondary"
data-bs-toggle="tooltip" data-bs-placement="top"
data-bs-custom-class="custom-tooltip"
title="This top tooltip is themed via CSS variables.">
data-bs-title="This top tooltip is themed via CSS variables.">
Custom tooltip
</button>
{{< /example >}}
Expand Down
2 changes: 1 addition & 1 deletion site/content/docs/5.2/forms/checks-radios.md
Expand Up @@ -36,7 +36,7 @@ Our checks use custom Bootstrap icons to indicate checked or indeterminate state

Checkboxes can utilize the `:indeterminate` pseudo class when manually set via JavaScript (there is no available HTML attribute for specifying it).

{{< example class="bd-example-indeterminate" js_snippet="true" >}}
{{< example class="bd-example-indeterminate" sb_js_snippet="true" >}}
<div class="form-check">
<input class="form-check-input" type="checkbox" value="" id="flexCheckIndeterminate">
<label class="form-check-label" for="flexCheckIndeterminate">
Expand Down
2 changes: 1 addition & 1 deletion site/layouts/partials/scripts.html
Expand Up @@ -30,7 +30,7 @@
// Get extra classes for this example except '.bd-example'
const classes = Array.from(event.target.closest('.bd-code-snippet').querySelector('.bd-example').classList).filter(x => x !== 'bd-example').join(' ')

const jsSnippet = event.target.closest('.bd-code-snippet').querySelector('.btn-edit').getAttribute('data-js-snippet')
const jsSnippet = event.target.closest('.bd-code-snippet').querySelector('.btn-edit').getAttribute('data-sb-js-snippet')
StackBlitzSDK.openBootstrapSnippet(htmlSnippet, jsSnippet, classes)
})
})
Expand Down
15 changes: 10 additions & 5 deletions site/layouts/shortcodes/example.html
Expand Up @@ -4,17 +4,20 @@
`args` are all optional and can be one of the following:
* id: the `div`'s id - default: ""
* class: any extra class(es) to be added to the `div` - default: ""
* js_snippet: add extra JS snippet to StackBlitz - default: `false`
* show_preview: if the preview should be output in the HTML - default: `true`
* lang: language used to display the code - default: "html"
* sb_hide: hide edit StackBlitz button - default `false`
* sb_js_snippet: add extra JS snippet to StackBlitz - default: `false`
* show_markup: if the markup should be output in the HTML - default: `true`
* show_preview: if the preview should be output in the HTML - default: `true`
*/ -}}

{{- $id := .Get "id" -}}
{{- $class := .Get "class" -}}
{{- $lang := .Get "lang" | default "html" -}}
{{- $show_preview := .Get "show_preview" | default true -}}
{{- $sb_hide := .Get "sb_hide" | default false -}}
{{- $sb_js_snippet := .Get "sb_js_snippet" | default false -}}
{{- $show_markup := .Get "show_markup" | default true -}}
{{- $js_snippet := .Get "js_snippet" | default false -}}
{{- $show_preview := .Get "show_preview" | default true -}}
{{- $input := .Inner -}}

<div class="bd-example-snippet bd-code-snippet">
Expand All @@ -29,9 +32,11 @@
<div class="d-flex align-items-center highlight-toolbar bg-light ps-3 pe-2 py-1">
<small class="font-monospace text-muted text-uppercase">{{- $lang -}}</small>
<div class="d-flex ms-auto">
<button type="button" class="btn-edit text-nowrap"{{ with $js_snippet }} data-js-snippet="{{ $js_snippet }}"{{ end }} title="Try it on StackBlitz">
{{- if eq $sb_hide false -}}
<button type="button" class="btn-edit text-nowrap"{{ with $sb_js_snippet }} data-sb-js-snippet="{{ $sb_js_snippet }}"{{ end }} title="Try it on StackBlitz">
<svg class="bi" role="img" aria-label="Try it"><use xlink:href="#lightning-charge-fill"/></svg>
</button>
{{- end -}}
<button type="button" class="btn-clipboard mt-0 me-0" title="Copy to clipboard">
<svg class="bi" role="img" aria-label="Copy"><use xlink:href="#clipboard"/></svg>
</button>
Expand Down

0 comments on commit 5ac36b6

Please sign in to comment.