@reuters-graphics/graphics-components 3.3.2 → 3.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/Byline/Byline.svelte +1 -8
- package/dist/components/LanguageButton/LanguageButton.svelte +91 -0
- package/dist/components/LanguageButton/LanguageButton.svelte.d.ts +19 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.js +6 -0
- package/package.json +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<!-- @component `Byline` [Read the docs.](https://reuters-graphics.github.io/graphics-components/?path=/docs/components-text-elements-byline--docs) -->
|
|
2
2
|
<script lang="ts">
|
|
3
|
-
import { getAuthorPageUrl } from '../../utils';
|
|
3
|
+
import { getAuthorPageUrl, formatTime } from '../../utils';
|
|
4
4
|
import Block from '../Block/Block.svelte';
|
|
5
5
|
import { apdate } from 'journalize';
|
|
6
6
|
import type { Snippet } from 'svelte';
|
|
@@ -74,13 +74,6 @@
|
|
|
74
74
|
return true;
|
|
75
75
|
};
|
|
76
76
|
|
|
77
|
-
const formatTime = (datetime: string) =>
|
|
78
|
-
new Date(datetime).toLocaleTimeString([], {
|
|
79
|
-
hour: '2-digit',
|
|
80
|
-
minute: '2-digit',
|
|
81
|
-
timeZoneName: 'short',
|
|
82
|
-
});
|
|
83
|
-
|
|
84
77
|
const areSameDay = (first: Date, second: Date) =>
|
|
85
78
|
first.getFullYear() === second.getFullYear() &&
|
|
86
79
|
first.getMonth() === second.getMonth() &&
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
<!-- @component `LanguageButton` [Read the docs.](https://reuters-graphics.github.io/graphics-components/?path=/docs/components-text-elements-languagebutton--docs) -->
|
|
2
|
+
<script lang="ts">
|
|
3
|
+
interface Props {
|
|
4
|
+
/** The current locale of the article */
|
|
5
|
+
locale: string | undefined;
|
|
6
|
+
/** Whether the article is embedded */
|
|
7
|
+
embedded?: boolean;
|
|
8
|
+
/** The base URL for the article */
|
|
9
|
+
base?: string;
|
|
10
|
+
/** Options for the language toggle button */
|
|
11
|
+
buttonOptions?: {
|
|
12
|
+
locale: string;
|
|
13
|
+
label: string;
|
|
14
|
+
};
|
|
15
|
+
/** Custom function for handling URL changes for locales and embed versions. */
|
|
16
|
+
setUrl?: () => string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
let {
|
|
20
|
+
locale = 'en',
|
|
21
|
+
embedded = false,
|
|
22
|
+
base,
|
|
23
|
+
buttonOptions = {
|
|
24
|
+
locale: 'es',
|
|
25
|
+
label: 'Leer en español',
|
|
26
|
+
},
|
|
27
|
+
setUrl,
|
|
28
|
+
}: Props = $props();
|
|
29
|
+
|
|
30
|
+
let translationLocale = buttonOptions.locale;
|
|
31
|
+
|
|
32
|
+
const handleLocale = () => {
|
|
33
|
+
if (setUrl) {
|
|
34
|
+
return setUrl();
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (embedded) {
|
|
38
|
+
if (locale === translationLocale) {
|
|
39
|
+
// If we're in the non-English article, link to the English article
|
|
40
|
+
return `${base}/embeds/en/page/`;
|
|
41
|
+
} else {
|
|
42
|
+
return `${base}/embeds/${translationLocale}/page`;
|
|
43
|
+
}
|
|
44
|
+
} else {
|
|
45
|
+
if (locale === translationLocale) {
|
|
46
|
+
// If we're in the non-English article, link to the English article
|
|
47
|
+
return `${base}/`;
|
|
48
|
+
} else {
|
|
49
|
+
return `${base}/${translationLocale}`;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
</script>
|
|
54
|
+
|
|
55
|
+
<div class="language-button">
|
|
56
|
+
<a data-sveltekit-reload href={handleLocale()}
|
|
57
|
+
><button
|
|
58
|
+
id="translate-button"
|
|
59
|
+
class="text-sm"
|
|
60
|
+
aria-label="Toggle article language"
|
|
61
|
+
>{locale === translationLocale ? 'Read in English' : (
|
|
62
|
+
buttonOptions.label
|
|
63
|
+
)}</button
|
|
64
|
+
></a
|
|
65
|
+
>
|
|
66
|
+
</div>
|
|
67
|
+
|
|
68
|
+
<style>div {
|
|
69
|
+
display: flex;
|
|
70
|
+
justify-content: center;
|
|
71
|
+
}
|
|
72
|
+
div #translate-button {
|
|
73
|
+
position: absolute;
|
|
74
|
+
font-weight: 500;
|
|
75
|
+
text-transform: uppercase;
|
|
76
|
+
letter-spacing: 0.06rem;
|
|
77
|
+
font-size: var(--theme-font-size-xs);
|
|
78
|
+
background-color: #d3e1e1;
|
|
79
|
+
color: rgb(91, 101, 101);
|
|
80
|
+
padding: 2px 12px;
|
|
81
|
+
border-radius: 4px;
|
|
82
|
+
z-index: 10;
|
|
83
|
+
cursor: pointer;
|
|
84
|
+
position: relative;
|
|
85
|
+
border: none;
|
|
86
|
+
transition: background-color 0.25s ease, color 0.25s ease;
|
|
87
|
+
}
|
|
88
|
+
div #translate-button:hover {
|
|
89
|
+
background-color: #889d9b;
|
|
90
|
+
color: #ebf7f7;
|
|
91
|
+
}</style>
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
interface Props {
|
|
2
|
+
/** The current locale of the article */
|
|
3
|
+
locale: string | undefined;
|
|
4
|
+
/** Whether the article is embedded */
|
|
5
|
+
embedded?: boolean;
|
|
6
|
+
/** The base URL for the article */
|
|
7
|
+
base?: string;
|
|
8
|
+
/** Options for the language toggle button */
|
|
9
|
+
buttonOptions?: {
|
|
10
|
+
locale: string;
|
|
11
|
+
label: string;
|
|
12
|
+
};
|
|
13
|
+
/** Custom function for handling URL changes for locales and embed versions. */
|
|
14
|
+
setUrl?: () => string;
|
|
15
|
+
}
|
|
16
|
+
/** `LanguageButton` [Read the docs.](https://reuters-graphics.github.io/graphics-components/?path=/docs/components-text-elements-languagebutton--docs) */
|
|
17
|
+
declare const LanguageButton: import("svelte").Component<Props, {}, "">;
|
|
18
|
+
type LanguageButton = ReturnType<typeof LanguageButton>;
|
|
19
|
+
export default LanguageButton;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { default as cssVariables } from './actions/cssVariables/index';
|
|
2
2
|
export { default as resizeObserver } from './actions/resizeObserver/index';
|
|
3
|
-
export { prettifyDate } from './utils/index';
|
|
3
|
+
export { prettifyDate, getAuthorPageUrl, formatTime } from './utils/index';
|
|
4
4
|
export { default as Analytics, registerPageview, } from './components/Analytics/Analytics.svelte';
|
|
5
5
|
export { default as Article } from './components/Article/Article.svelte';
|
|
6
6
|
export { default as BlogPost } from './components/BlogPost/BlogPost.svelte';
|
|
@@ -25,6 +25,7 @@ export { default as EndNotes } from './components/EndNotes/EndNotes.svelte';
|
|
|
25
25
|
export { default as InfoBox } from './components/InfoBox/InfoBox.svelte';
|
|
26
26
|
export { default as InlineAd } from './components/AdSlot/InlineAd.svelte';
|
|
27
27
|
export { default as KinesisLogo } from './components/KinesisLogo/KinesisLogo.svelte';
|
|
28
|
+
export { default as LanguageButton } from './components/LanguageButton/LanguageButton.svelte';
|
|
28
29
|
export { default as LeaderboardAd } from './components/AdSlot/LeaderboardAd.svelte';
|
|
29
30
|
export { default as TileMap } from './components/TileMap/TileMap.svelte';
|
|
30
31
|
export { default as TileMapLayer } from './components/TileMap/TileMapLayer.svelte';
|
package/dist/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
export { default as cssVariables } from './actions/cssVariables/index';
|
|
3
3
|
export { default as resizeObserver } from './actions/resizeObserver/index';
|
|
4
4
|
// Utils
|
|
5
|
-
export { prettifyDate } from './utils/index';
|
|
5
|
+
export { prettifyDate, getAuthorPageUrl, formatTime } from './utils/index';
|
|
6
6
|
// Components
|
|
7
7
|
export { default as Analytics, registerPageview, } from './components/Analytics/Analytics.svelte';
|
|
8
8
|
export { default as Article } from './components/Article/Article.svelte';
|
|
@@ -28,6 +28,7 @@ export { default as EndNotes } from './components/EndNotes/EndNotes.svelte';
|
|
|
28
28
|
export { default as InfoBox } from './components/InfoBox/InfoBox.svelte';
|
|
29
29
|
export { default as InlineAd } from './components/AdSlot/InlineAd.svelte';
|
|
30
30
|
export { default as KinesisLogo } from './components/KinesisLogo/KinesisLogo.svelte';
|
|
31
|
+
export { default as LanguageButton } from './components/LanguageButton/LanguageButton.svelte';
|
|
31
32
|
export { default as LeaderboardAd } from './components/AdSlot/LeaderboardAd.svelte';
|
|
32
33
|
export { default as TileMap } from './components/TileMap/TileMap.svelte';
|
|
33
34
|
export { default as TileMapLayer } from './components/TileMap/TileMapLayer.svelte';
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -31,3 +31,5 @@ export declare const prettifyDate: (input: string) => string;
|
|
|
31
31
|
* @returns The slugified string.
|
|
32
32
|
*/
|
|
33
33
|
export declare const slugify: (str: string) => string;
|
|
34
|
+
/** Formats a datetime string into a localized time string with hour, minute, and time zone for the dateline */
|
|
35
|
+
export declare const formatTime: (datetime: string) => string;
|
package/dist/utils/index.js
CHANGED
|
@@ -86,3 +86,9 @@ const prettifyAmPm = (text) => {
|
|
|
86
86
|
* @returns The slugified string.
|
|
87
87
|
*/
|
|
88
88
|
export const slugify = (str) => slug(str, { lower: true, strict: true });
|
|
89
|
+
/** Formats a datetime string into a localized time string with hour, minute, and time zone for the dateline */
|
|
90
|
+
export const formatTime = (datetime) => new Date(datetime).toLocaleTimeString([], {
|
|
91
|
+
hour: '2-digit',
|
|
92
|
+
minute: '2-digit',
|
|
93
|
+
timeZoneName: 'short',
|
|
94
|
+
});
|