1
0
Fork 0
mirror of https://github.com/codex-team/codex.docs.git synced 2025-07-29 18:19:42 +02:00

feat: add reusable copy button component

This commit is contained in:
Aleksey Solovyev 2022-11-29 14:07:20 +03:00
parent 91ba44a169
commit 285b94779f
4 changed files with 166 additions and 2 deletions

View file

@ -0,0 +1,25 @@
{#
Reusable copy button component.
Available props:
- ariaLabel: label for better accessibility
- class: additional class for the button
- textToCopy: text to be copied to the clipboard (use '#' for anchor links)
Usage examples:
{% include 'components/copy-button.twig' with { textToCopy: 'Lorem ipsum dolor' } %}
{% include 'components/copy-button.twig' with { textToCopy: '#anchor-link-dolor' } %}
#}
{% set attrNameForTextToCopy = 'data-text-to-copy' %}
{% set ariaLabel = ariaLabel ?? 'Copy to the Clipboard' %}
{% set mainTag = 'button' %}
{% set mainClass = 'copy-button' %}
<{{ mainTag }} class="{{ mainClass }} {{ class ?? '' }}" aria-label="{{ ariaLabel }}" {{ attrNameForTextToCopy }}="{{ textToCopy }}">
<div class="{{ mainClass }}__inner">
<div class="{{ mainClass }}__icon--initial">{{ svg('copy') }}</div>
<div class="{{ mainClass }}__icon--success">{{ svg('check') }}</div>
</div>
</{{ mainTag }}>