Origami Frontend Components & Services

Readme: o-share

Social media buttons.

Overview

Usage

Check out how to include Origami components in your project to get started with o-share.

Markup

The following markup is the simplest but requires JavaScript to work and does not support custom share icons or icon labels. If your project requires either of those features see the full markup section.

<div data-o-component="o-share"
    class="o-share"
    data-o-share-links="{{links}}"
    data-o-share-url="{{url}}"
    data-o-share-title="{{title}}"
    data-o-share-titleExtra="{{titleExtra}}"
    data-o-share-summary="{{summary}}"
    data-o-share-relatedTwitterAccounts="{{relatedTwitterAccounts}}"
    data-o-share-location="{{locationOfShareComponent}}">
</div>

The different social networks are (in the order suggested by the design team):

Small

Add the o-share--small class for smaller icons. This is useful when including multiple instances of o-share to share items within a page, rather than to share the current page itself.

-<div data-o-component="o-share" class="o-share">
+<div data-o-component="o-share" class="o-share o-share--small">
    <!-- more o-share markup -->
</div>

Full Markup

Include the complete markup, available in the Origami registry directly to:

<!-- see the registry demos for full markup -->
<div data-o-component="o-share" class="o-share">
    <ul>
        <!-- a share to twitter action example -->
        <!-- href tag is not shown, see the registry demos for full markup  -->
        <li class="o-share__action">
            <a class="o-share__icon o-share__icon--twitter"
                href="#twitter-link-here"
                rel="noopener">
                <span class="o-share__text">Twitter</span>
            </a>
        </li>
        <!-- more o-share actions -->
    </ul>
</div>

Open In A New Tab

Social share actions open in the same frame, but you may add target="_blank" to the <a> element if your project requires share links are opened in a new tab/window where supported.

Text Labels

Add the o-share__action--labelled class to any share action to display the action text alongside the icon. This example uses the twitter action, but we recommend this only for custom actions which are less recognisable compared with big social media brands.

<!-- see the registry demos for a full markup example -->
<div data-o-component="o-share" class="o-share">
    <ul>
-        <li class="o-share__action">
+        <li class="o-share__action o-share__action--labelled">
            <a class="o-share__icon o-share__icon--twitter"
                href="#twitter-link-here"
                rel="noopener">
                <span class="o-share__text">Twitter</span>
            </a>
        </li>
        <!-- more o-share actions -->
    </ul>
</div>

Custom Actions

Form markup is allowed within the o-share__action label to to handle custom share actions.

<!-- see the registry demos for full markup -->
<div data-o-component="o-share" class="o-share">
    <ul>
        <!-- a custom share action example which includes a text label -->
        <li class="o-share__action o-share__action--labelled">
            <!-- form markup is allowed to handle custom share actions -->
            <form method="POST" action="#">
                <button type="submit" class="o-share__icon o-share__icon--share">
                    <span class="o-share__text">Save</span>
                </button>
            </form>
        </li>
        <!-- more o-share actions -->
    </ul>
</div>

The share icon is made available by default for custom share features as shown in the Origami registry demos.

Sass

@import 'o-share/main';

The oShare mixin is used to output the o-share styles.

@include oShare();

We recommend passing the oShare mixin an optional argument $opts, to specify styles granularly and keep your CSS bundle small.

For example:

@include oShare($opts: (
    'sizes': ('small'), // output styles for a small variation of o-share i.e. o-share--small
    'vertical': true, // output styles for a vertical o-share i.e. o-share--vertical
    'icons': ('twitter', 'facebook', 'whatsapp') // output styles for select share icons
));

All $opts options include:

Colour Usecases

o-share sets custom colour usecases for matching the colour of share buttons. These usecases are limited, for example they do not provide colours for the inverse variant, and not recommended for new projects (it is possible to output custom icons using the oShare mixin, without matching colours).

Usecase Property Uses
o-share/default-icon background, border, text Default colours, used by icons without a state (e.g. before hover).
o-share/ft-icon background, border, text Colours to highlight FT icon social buttons like email (e.g. on hover).
o-share/[social-icon-name]-icon background, border, text Colours to highlight social buttons with a brand, like Twitter (e.g. o-share/twitter-icon on hover).

Use the oColorsByUsecase mixin from o-colors to retrieve custom colour usecases set by o-share.

.my-icon:hover {
    background-color: oColorsByUsecase('o-share/ft-icon', 'background');
}

JavaScript

To instantiate the JavaScript:

var oShare = require('o-share');
var oShareInstance = new oShare(document.querySelector('[data-o-component=o-share]'));

The markup will be generated for that instance of o-share.

You can also instantiate all instances in your page by running oShare.init which returns an array with all of them.

Alternatively, an o.DOMContentLoaded event can be dispatched on the document to run #init():

document.addEventListener("DOMContentLoaded", function() {
    document.dispatchEvent(new CustomEvent('o.DOMContentLoaded'));
});

Check out the API docs

Events

The following events are fired by o-share.

oShare.ready

oShare.ready fires when a o-share instance has been initialised.

The event provides the following properties:

oShare.open

oShare.open fires when a social network share action is triggered, to open a new window.

The event provides the following properties:


Migration guide

State Major Version Last Minor Release Migration guide
✨ active 7 N/A migrate to v7
⚠ maintained 6 6.5 migrate to v6
╳ deprecated 5 5.0 migrate to v5
╳ deprecated 4 4.0 migrate to v4
╳ deprecated 3 3.0 migrate to v3
╳ deprecated 2 2.1 -
╳ deprecated 1 1.7 -

Contact

If you have any questions or comments about this component, or need help using it, please either raise an issue, visit #origami-support or email Origami Support.


Licence

This software is published by the Financial Times under the MIT licence.

Support Status
active
Switch component view

GitHub Repository

Install o-share

If using the Build Service, add o-share@^7.4.7 to your script and link tags.

If running a Manual Build, run bower install --save "o-share@^7.4.7".

Help & Support

o-share is maintained directly by the Origami team. If you have any questions about o-share or Origami in general, we are happy to help. 😊

Slack: #origami-support
Email: origami.support@ft.com

Feedback / Issues

To report a bug or request features please create an issue on Github. For support or general feedback please get in touch 😊

Slack: #origami-support
Email: origami.support@ft.com