14.7.7 • Published 11 months ago

@financial-times/x-article-save-button v14.7.7

Weekly downloads
479
License
ISC
Repository
-
Last release
11 months ago

Article Save Button

This module provides a template for myFT save article buttons, and is intended to replace the legacy handlebars component in n-myft-ui.

Installation

npm install --save @financial-times/x-article-save-button

Props

(Some of the properties don't influence the way button looks or acts, but can be used for e.g. client-side Javascript in the apps).

FeatureTypeRequiredDefault valueDescription
contentIdStringyesnoneUUID of the article
contentTitleStringyesnoneTitle of the article
savedBooleannofalseWhether the article is saved or not.
csrfTokenStringnononeCSRF token (will be included in a hidden form field).
trackableIdStringno'save-for-later'Identifier for tracking purposes

Usage

The components provided by this module are all functions that expect a map of teaser properties. They can be used with vanilla JavaScript or JSX (If you are not familiar check out WTF is JSX first). For example if you were writing your application using React you could use the component like this:

import React from 'react';
import { ArticleSaveButton } from '@financial-times/x-article-save-button';

// A == B == C
const a = ArticleSaveButton(props);
const b = <ArticleSaveButton {...props} />;
const c = React.createElement(ArticleSaveButton, props);

All x- components are designed to be compatible with a variety of runtimes, not just React. Check out the x-engine documentation for a list of recommended libraries and frameworks.

Client side behaviour

For users with JavaScript enabled, the default form submit action is prevented, and a custom event (named 'x-article-save-button') will be dispatched on the form element.

This custom event will contain the following in its detail object:

PropertyValue
actionadd or remove
actorTypeuser
relationshipNamesaved
subjectTypecontent
subjectIdthe value of the contentId prop
tokenthe value of the csrfToken prop

It is up to the consumer of this component to listen for the x-article-save-button event, and use this data, along with the user's ID, and carry out the appropriate action.

For example, if using next-myft-client:

import nextMyftClient from 'next-myft-client';

document.body.addEventListener('x-article-save-button', ({ detail }) => {
	nextMyftClient[detail.action](detail.actorType, null, detail.relationshipName, detail.subjectType, detail.subjectId, {
		token: detail.token
	});
});
14.7.7

11 months ago

14.7.6

11 months ago

14.7.5

1 year ago

14.7.4

1 year ago

14.7.3

1 year ago

14.7.2

1 year ago

14.7.1

1 year ago

14.7.0

1 year ago

14.6.5

1 year ago

14.6.3

1 year ago

14.6.4

1 year ago

14.6.2

1 year ago

14.6.0

1 year ago

14.6.1

1 year ago

14.5.2

1 year ago

14.5.0

1 year ago

14.5.1

1 year ago

14.4.2

1 year ago

14.4.1

1 year ago

14.4.0

1 year ago

14.3.1

1 year ago

14.3.0

2 years ago

14.2.0

2 years ago

12.0.0-beta.2

2 years ago

12.0.0-beta.3

2 years ago

12.0.0-beta.1

2 years ago

14.1.0

2 years ago

14.1.1

2 years ago

14.1.2

2 years ago

12.0.0

2 years ago

12.0.1

2 years ago

12.0.2

2 years ago

11.2.0

2 years ago

12.0.1-beta.1

2 years ago

14.0.0

2 years ago

14.0.1

2 years ago

13.0.0

2 years ago

14.0.2

2 years ago

13.0.1

2 years ago

14.0.3

2 years ago

14.0.4

2 years ago

11.1.1

2 years ago

11.1.2

2 years ago

11.1.0

2 years ago

10.5.0

2 years ago

10.4.0

2 years ago

11.0.0

2 years ago

10.3.0

2 years ago

10.0.0

2 years ago

10.1.0

2 years ago

10.2.0

2 years ago

10.1.1

2 years ago

10.1.2

2 years ago

8.2.3

3 years ago

8.2.2

3 years ago

8.2.5

3 years ago

8.2.4

3 years ago

8.2.1

3 years ago

8.2.0

3 years ago

8.1.1

3 years ago

8.1.0

3 years ago

8.0.5

3 years ago

8.0.4

3 years ago

8.0.6

3 years ago

8.0.3

3 years ago

8.0.2

3 years ago

6.8.2-beta.1

3 years ago

8.0.1

3 years ago

8.0.0

3 years ago

8.0.1-beta.1

3 years ago

6.8.1

3 years ago

7.0.0

3 years ago

6.8.0

3 years ago

6.7.1

3 years ago

0.0.13

4 years ago

0.0.11

7 years ago

0.0.10

7 years ago

0.0.9

7 years ago

0.0.8

7 years ago

0.0.7

7 years ago

0.0.6

7 years ago

0.0.5

7 years ago

0.0.4

7 years ago

0.0.2

7 years ago