14.7.4 • Published 1 day ago

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

Weekly downloads
479
License
ISC
Repository
-
Last release
1 day 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.4

1 day ago

14.7.3

7 days ago

14.7.2

22 days ago

14.7.1

1 month ago

14.7.0

1 month ago

14.6.5

1 month ago

14.6.3

2 months ago

14.6.4

2 months ago

14.6.2

2 months ago

14.6.0

2 months ago

14.6.1

2 months ago

14.5.2

3 months ago

14.5.0

3 months ago

14.5.1

3 months ago

14.4.2

3 months ago

14.4.1

4 months ago

14.4.0

4 months ago

14.3.1

4 months ago

14.3.0

4 months ago

14.2.0

5 months ago

12.0.0-beta.2

11 months ago

12.0.0-beta.3

10 months ago

12.0.0-beta.1

11 months ago

14.1.0

6 months ago

14.1.1

6 months ago

14.1.2

6 months ago

12.0.0

10 months ago

12.0.1

10 months ago

12.0.2

9 months ago

11.2.0

11 months ago

12.0.1-beta.1

11 months ago

14.0.0

9 months ago

14.0.1

8 months ago

13.0.0

9 months ago

14.0.2

8 months ago

13.0.1

9 months ago

14.0.3

8 months ago

14.0.4

7 months ago

11.1.1

12 months ago

11.1.2

11 months ago

11.1.0

12 months ago

10.5.0

1 year ago

10.4.0

1 year ago

11.0.0

1 year ago

10.3.0

1 year ago

10.0.0

1 year ago

10.1.0

1 year ago

10.2.0

1 year ago

10.1.1

1 year ago

10.1.2

1 year ago

8.2.3

1 year ago

8.2.2

2 years ago

8.2.5

1 year ago

8.2.4

1 year ago

8.2.1

2 years ago

8.2.0

2 years ago

8.1.1

2 years ago

8.1.0

2 years ago

8.0.5

2 years ago

8.0.4

2 years ago

8.0.6

2 years ago

8.0.3

2 years ago

8.0.2

2 years ago

6.8.2-beta.1

2 years ago

8.0.1

2 years ago

8.0.0

2 years ago

8.0.1-beta.1

2 years ago

6.8.1

2 years ago

7.0.0

2 years ago

6.8.0

2 years ago

6.7.1

2 years ago

0.0.13

2 years ago

0.0.11

5 years ago

0.0.10

5 years ago

0.0.9

5 years ago

0.0.8

5 years ago

0.0.7

5 years ago

0.0.6

6 years ago

0.0.5

6 years ago

0.0.4

6 years ago

0.0.2

6 years ago