@ndla/ui 56.0.122-alpha.0 → 56.0.124-alpha.0
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/README.md +1 -1
- package/es/Article/Article.js +127 -0
- package/es/Article/Article.js.map +1 -0
- package/es/Article/ArticleByline.js +133 -0
- package/es/Article/ArticleByline.js.map +1 -0
- package/es/Article/ArticleFootNotes.js +40 -0
- package/es/Article/ArticleFootNotes.js.map +1 -0
- package/es/AudioPlayer/AudioPlayer.js +157 -0
- package/es/AudioPlayer/AudioPlayer.js.map +1 -0
- package/es/AudioPlayer/Controls.js +254 -0
- package/es/AudioPlayer/Controls.js.map +1 -0
- package/es/AudioPlayer/SpeechControl.js +40 -0
- package/es/AudioPlayer/SpeechControl.js.map +1 -0
- package/es/AudioPlayer/index.js +8 -0
- package/es/AudioPlayer/index.js.map +1 -0
- package/es/Breadcrumb/Breadcrumb.js +44 -0
- package/es/Breadcrumb/Breadcrumb.js.map +1 -0
- package/es/Breadcrumb/BreadcrumbItem.js +36 -0
- package/es/Breadcrumb/BreadcrumbItem.js.map +1 -0
- package/es/Breadcrumb/HomeBreadcrumb.js +44 -0
- package/es/Breadcrumb/HomeBreadcrumb.js.map +1 -0
- package/es/Breadcrumb/index.js +9 -0
- package/es/Breadcrumb/index.js.map +1 -0
- package/es/CampaignBlock/CampaignBlock.js +131 -0
- package/es/CampaignBlock/CampaignBlock.js.map +1 -0
- package/es/CodeBlock/CodeBlock.js +25 -0
- package/es/CodeBlock/CodeBlock.js.map +1 -0
- package/es/CodeBlock/codeLanguageOptions.js +114 -0
- package/es/CodeBlock/codeLanguageOptions.js.map +1 -0
- package/es/Concept/Concept.js +50 -0
- package/es/Concept/Concept.js.map +1 -0
- package/es/ContactBlock/ContactBlock.js +145 -0
- package/es/ContactBlock/ContactBlock.js.map +1 -0
- package/es/ContentTypeBadge/ContentTypeBadge.js +41 -0
- package/es/ContentTypeBadge/ContentTypeBadge.js.map +1 -0
- package/es/ContentTypeBlockQuote/ContentTypeBlockQuote.js +25 -0
- package/es/ContentTypeBlockQuote/ContentTypeBlockQuote.js.map +1 -0
- package/es/ContentTypeFramedContent/ContentTypeFramedContent.js +25 -0
- package/es/ContentTypeFramedContent/ContentTypeFramedContent.js.map +1 -0
- package/es/ContentTypeHero/ContentTypeHero.js +39 -0
- package/es/ContentTypeHero/ContentTypeHero.js.map +1 -0
- package/es/CopyParagraphButton/CopyParagraphButton.js +62 -0
- package/es/CopyParagraphButton/CopyParagraphButton.js.map +1 -0
- package/es/CopyParagraphButton/index.js +8 -0
- package/es/CopyParagraphButton/index.js.map +1 -0
- package/es/Embed/AudioEmbed.js +52 -0
- package/es/Embed/AudioEmbed.js.map +1 -0
- package/es/Embed/BrightcoveEmbed.js +96 -0
- package/es/Embed/BrightcoveEmbed.js.map +1 -0
- package/es/Embed/CodeEmbed.js +61 -0
- package/es/Embed/CodeEmbed.js.map +1 -0
- package/es/Embed/ConceptEmbed.js +78 -0
- package/es/Embed/ConceptEmbed.js.map +1 -0
- package/es/Embed/ConceptInlineTriggerButton.js +40 -0
- package/es/Embed/ConceptInlineTriggerButton.js.map +1 -0
- package/es/Embed/ContentLinkEmbed.js +31 -0
- package/es/Embed/ContentLinkEmbed.js.map +1 -0
- package/es/Embed/CopyrightEmbed.js +23 -0
- package/es/Embed/CopyrightEmbed.js.map +1 -0
- package/es/Embed/EmbedErrorPlaceholder.js +43 -0
- package/es/Embed/EmbedErrorPlaceholder.js.map +1 -0
- package/es/Embed/EmbedWrapper.js +26 -0
- package/es/Embed/EmbedWrapper.js.map +1 -0
- package/es/Embed/ExternalEmbed.js +54 -0
- package/es/Embed/ExternalEmbed.js.map +1 -0
- package/es/Embed/FootnoteEmbed.js +27 -0
- package/es/Embed/FootnoteEmbed.js.map +1 -0
- package/es/Embed/GlossEmbed.js +52 -0
- package/es/Embed/GlossEmbed.js.map +1 -0
- package/es/Embed/H5pEmbed.js +38 -0
- package/es/Embed/H5pEmbed.js.map +1 -0
- package/es/Embed/IframeEmbed.js +69 -0
- package/es/Embed/IframeEmbed.js.map +1 -0
- package/es/Embed/ImageEmbed.js +180 -0
- package/es/Embed/ImageEmbed.js.map +1 -0
- package/es/Embed/InlineTriggerButton.js +25 -0
- package/es/Embed/InlineTriggerButton.js.map +1 -0
- package/es/Embed/RelatedContentEmbed.js +38 -0
- package/es/Embed/RelatedContentEmbed.js.map +1 -0
- package/es/Embed/UnknownEmbed.js +20 -0
- package/es/Embed/UnknownEmbed.js.map +1 -0
- package/es/Embed/UuDisclaimerEmbed.js +54 -0
- package/es/Embed/UuDisclaimerEmbed.js.map +1 -0
- package/es/ErrorMessage/ErrorMessage.js +54 -0
- package/es/ErrorMessage/ErrorMessage.js.map +1 -0
- package/es/ErrorMessage/index.js +8 -0
- package/es/ErrorMessage/index.js.map +1 -0
- package/es/FactBox/FactBox.js +121 -0
- package/es/FactBox/FactBox.js.map +1 -0
- package/es/FactBox/index.js +8 -0
- package/es/FactBox/index.js.map +1 -0
- package/es/FileList/File.js +76 -0
- package/es/FileList/File.js.map +1 -0
- package/es/FileList/FileList.js +32 -0
- package/es/FileList/FileList.js.map +1 -0
- package/es/FileList/PdfFile.js +28 -0
- package/es/FileList/PdfFile.js.map +1 -0
- package/es/Gloss/Gloss.js +142 -0
- package/es/Gloss/Gloss.js.map +1 -0
- package/es/Gloss/GlossExample.js +46 -0
- package/es/Gloss/GlossExample.js.map +1 -0
- package/es/Grid/Grid.js +66 -0
- package/es/Grid/Grid.js.map +1 -0
- package/es/Grid/GridParallaxItem.js +21 -0
- package/es/Grid/GridParallaxItem.js.map +1 -0
- package/es/KeyFigure/KeyFigure.js +46 -0
- package/es/KeyFigure/KeyFigure.js.map +1 -0
- package/es/LicenseByline/EmbedByline.js +132 -0
- package/es/LicenseByline/EmbedByline.js.map +1 -0
- package/es/LicenseByline/LicenseLink.js +31 -0
- package/es/LicenseByline/LicenseLink.js.map +1 -0
- package/es/LinkBlock/LinkBlock.js +74 -0
- package/es/LinkBlock/LinkBlock.js.map +1 -0
- package/es/LinkBlock/LinkBlockSection.js +23 -0
- package/es/LinkBlock/LinkBlockSection.js.map +1 -0
- package/es/Pitch/Pitch.js +62 -0
- package/es/Pitch/Pitch.js.map +1 -0
- package/es/RelatedArticleList/RelatedArticleList.js +97 -0
- package/es/RelatedArticleList/RelatedArticleList.js.map +1 -0
- package/es/RelatedArticleList/index.js +8 -0
- package/es/RelatedArticleList/index.js.map +1 -0
- package/es/ResourceBox/ResourceBox.js +74 -0
- package/es/ResourceBox/ResourceBox.js.map +1 -0
- package/es/TagSelector/TagSelector.js +100 -0
- package/es/TagSelector/TagSelector.js.map +1 -0
- package/es/ZendeskButton/ZendeskButton.js +41 -0
- package/es/ZendeskButton/ZendeskButton.js.map +1 -0
- package/es/_virtual/rolldown_runtime.js +11 -0
- package/es/i18n/formatNestedMessages.js +17 -0
- package/es/i18n/formatNestedMessages.js.map +1 -0
- package/es/i18n/i18n.js +29 -0
- package/es/i18n/i18n.js.map +1 -0
- package/es/i18n/useComponentTranslations.js +155 -0
- package/es/i18n/useComponentTranslations.js.map +1 -0
- package/es/index.js +65 -0
- package/es/locale/messages-en.js +438 -0
- package/es/locale/messages-en.js.map +1 -0
- package/es/locale/messages-nb.js +438 -0
- package/es/locale/messages-nb.js.map +1 -0
- package/es/locale/messages-nn.js +438 -0
- package/es/locale/messages-nn.js.map +1 -0
- package/es/locale/messages-se.js +438 -0
- package/es/locale/messages-se.js.map +1 -0
- package/es/model/ContentType.js +72 -0
- package/es/model/ContentType.js.map +1 -0
- package/es/model/SubjectCategories.js +25 -0
- package/es/model/SubjectCategories.js.map +1 -0
- package/es/model/SubjectTypes.js +23 -0
- package/es/model/SubjectTypes.js.map +1 -0
- package/es/model/WordClass.js +53 -0
- package/es/model/WordClass.js.map +1 -0
- package/es/model/index.js +19 -0
- package/es/model/index.js.map +1 -0
- package/es/utils/licenseAttributes.js +16 -0
- package/es/utils/licenseAttributes.js.map +1 -0
- package/es/utils/relativeUrl.js +26 -0
- package/es/utils/relativeUrl.js.map +1 -0
- package/lib/Article/Article.js +134 -0
- package/lib/Article/Article.js.map +1 -0
- package/lib/Article/ArticleByline.js +135 -0
- package/lib/Article/ArticleByline.js.map +1 -0
- package/lib/Article/ArticleFootNotes.js +41 -0
- package/lib/Article/ArticleFootNotes.js.map +1 -0
- package/lib/AudioPlayer/AudioPlayer.js +158 -0
- package/lib/AudioPlayer/AudioPlayer.js.map +1 -0
- package/lib/AudioPlayer/Controls.js +255 -0
- package/lib/AudioPlayer/Controls.js.map +1 -0
- package/lib/AudioPlayer/SpeechControl.js +41 -0
- package/lib/AudioPlayer/SpeechControl.js.map +1 -0
- package/lib/AudioPlayer/index.js +8 -0
- package/lib/AudioPlayer/index.js.map +1 -0
- package/lib/Breadcrumb/Breadcrumb.js +45 -0
- package/lib/Breadcrumb/Breadcrumb.js.map +1 -0
- package/lib/Breadcrumb/BreadcrumbItem.js +37 -0
- package/lib/Breadcrumb/BreadcrumbItem.js.map +1 -0
- package/lib/Breadcrumb/HomeBreadcrumb.js +45 -0
- package/lib/Breadcrumb/HomeBreadcrumb.js.map +1 -0
- package/lib/Breadcrumb/index.js +9 -0
- package/lib/Breadcrumb/index.js.map +1 -0
- package/lib/CampaignBlock/CampaignBlock.js +132 -0
- package/lib/CampaignBlock/CampaignBlock.js.map +1 -0
- package/lib/CodeBlock/CodeBlock.js +26 -0
- package/lib/CodeBlock/CodeBlock.js.map +1 -0
- package/lib/CodeBlock/codeLanguageOptions.js +115 -0
- package/lib/CodeBlock/codeLanguageOptions.js.map +1 -0
- package/lib/Concept/Concept.js +51 -0
- package/lib/Concept/Concept.js.map +1 -0
- package/lib/ContactBlock/ContactBlock.js +147 -0
- package/lib/ContactBlock/ContactBlock.js.map +1 -0
- package/lib/ContentTypeBadge/ContentTypeBadge.js +43 -0
- package/lib/ContentTypeBadge/ContentTypeBadge.js.map +1 -0
- package/lib/ContentTypeBlockQuote/ContentTypeBlockQuote.js +26 -0
- package/lib/ContentTypeBlockQuote/ContentTypeBlockQuote.js.map +1 -0
- package/lib/ContentTypeFramedContent/ContentTypeFramedContent.js +26 -0
- package/lib/ContentTypeFramedContent/ContentTypeFramedContent.js.map +1 -0
- package/lib/ContentTypeHero/ContentTypeHero.js +40 -0
- package/lib/ContentTypeHero/ContentTypeHero.js.map +1 -0
- package/lib/CopyParagraphButton/CopyParagraphButton.js +63 -0
- package/lib/CopyParagraphButton/CopyParagraphButton.js.map +1 -0
- package/lib/CopyParagraphButton/index.js +8 -0
- package/lib/CopyParagraphButton/index.js.map +1 -0
- package/lib/Embed/AudioEmbed.js +53 -0
- package/lib/Embed/AudioEmbed.js.map +1 -0
- package/lib/Embed/BrightcoveEmbed.js +97 -0
- package/lib/Embed/BrightcoveEmbed.js.map +1 -0
- package/lib/Embed/CodeEmbed.js +62 -0
- package/lib/Embed/CodeEmbed.js.map +1 -0
- package/lib/Embed/ConceptEmbed.js +81 -0
- package/lib/Embed/ConceptEmbed.js.map +1 -0
- package/lib/Embed/ConceptInlineTriggerButton.js +41 -0
- package/lib/Embed/ConceptInlineTriggerButton.js.map +1 -0
- package/lib/Embed/ContentLinkEmbed.js +32 -0
- package/lib/Embed/ContentLinkEmbed.js.map +1 -0
- package/lib/Embed/CopyrightEmbed.js +24 -0
- package/lib/Embed/CopyrightEmbed.js.map +1 -0
- package/lib/Embed/EmbedErrorPlaceholder.js +44 -0
- package/lib/Embed/EmbedErrorPlaceholder.js.map +1 -0
- package/lib/Embed/EmbedWrapper.js +27 -0
- package/lib/Embed/EmbedWrapper.js.map +1 -0
- package/lib/Embed/ExternalEmbed.js +55 -0
- package/lib/Embed/ExternalEmbed.js.map +1 -0
- package/lib/Embed/FootnoteEmbed.js +28 -0
- package/lib/Embed/FootnoteEmbed.js.map +1 -0
- package/lib/Embed/GlossEmbed.js +53 -0
- package/lib/Embed/GlossEmbed.js.map +1 -0
- package/lib/Embed/H5pEmbed.js +39 -0
- package/lib/Embed/H5pEmbed.js.map +1 -0
- package/lib/Embed/IframeEmbed.js +70 -0
- package/lib/Embed/IframeEmbed.js.map +1 -0
- package/lib/Embed/ImageEmbed.js +183 -0
- package/lib/Embed/ImageEmbed.js.map +1 -0
- package/lib/Embed/InlineTriggerButton.js +26 -0
- package/lib/Embed/InlineTriggerButton.js.map +1 -0
- package/lib/Embed/RelatedContentEmbed.js +39 -0
- package/lib/Embed/RelatedContentEmbed.js.map +1 -0
- package/lib/Embed/UnknownEmbed.js +21 -0
- package/lib/Embed/UnknownEmbed.js.map +1 -0
- package/lib/Embed/UuDisclaimerEmbed.js +55 -0
- package/lib/Embed/UuDisclaimerEmbed.js.map +1 -0
- package/lib/ErrorMessage/ErrorMessage.js +55 -0
- package/lib/ErrorMessage/ErrorMessage.js.map +1 -0
- package/lib/ErrorMessage/index.js +8 -0
- package/lib/ErrorMessage/index.js.map +1 -0
- package/lib/FactBox/FactBox.js +122 -0
- package/lib/FactBox/FactBox.js.map +1 -0
- package/lib/FactBox/index.js +8 -0
- package/lib/FactBox/index.js.map +1 -0
- package/lib/FileList/File.js +78 -0
- package/lib/FileList/File.js.map +1 -0
- package/lib/FileList/FileList.js +35 -0
- package/lib/FileList/FileList.js.map +1 -0
- package/lib/FileList/PdfFile.js +29 -0
- package/lib/FileList/PdfFile.js.map +1 -0
- package/lib/Gloss/Gloss.js +143 -0
- package/lib/Gloss/Gloss.js.map +1 -0
- package/lib/Gloss/GlossExample.js +47 -0
- package/lib/Gloss/GlossExample.js.map +1 -0
- package/lib/Grid/Grid.js +67 -0
- package/lib/Grid/Grid.js.map +1 -0
- package/lib/Grid/GridParallaxItem.js +22 -0
- package/lib/Grid/GridParallaxItem.js.map +1 -0
- package/lib/KeyFigure/KeyFigure.js +47 -0
- package/lib/KeyFigure/KeyFigure.js.map +1 -0
- package/lib/LicenseByline/EmbedByline.js +134 -0
- package/lib/LicenseByline/EmbedByline.js.map +1 -0
- package/lib/LicenseByline/LicenseLink.js +32 -0
- package/lib/LicenseByline/LicenseLink.js.map +1 -0
- package/lib/LinkBlock/LinkBlock.js +75 -0
- package/lib/LinkBlock/LinkBlock.js.map +1 -0
- package/lib/LinkBlock/LinkBlockSection.js +24 -0
- package/lib/LinkBlock/LinkBlockSection.js.map +1 -0
- package/lib/Pitch/Pitch.js +63 -0
- package/lib/Pitch/Pitch.js.map +1 -0
- package/lib/RelatedArticleList/RelatedArticleList.js +99 -0
- package/lib/RelatedArticleList/RelatedArticleList.js.map +1 -0
- package/lib/RelatedArticleList/index.js +8 -0
- package/lib/RelatedArticleList/index.js.map +1 -0
- package/lib/ResourceBox/ResourceBox.js +75 -0
- package/lib/ResourceBox/ResourceBox.js.map +1 -0
- package/lib/TagSelector/TagSelector.js +108 -0
- package/lib/TagSelector/TagSelector.js.map +1 -0
- package/lib/ZendeskButton/ZendeskButton.js +42 -0
- package/lib/ZendeskButton/ZendeskButton.js.map +1 -0
- package/lib/_virtual/rolldown_runtime.js +42 -0
- package/lib/i18n/formatNestedMessages.js +18 -0
- package/lib/i18n/formatNestedMessages.js.map +1 -0
- package/lib/i18n/i18n.js +31 -0
- package/lib/i18n/i18n.js.map +1 -0
- package/lib/i18n/useComponentTranslations.js +163 -0
- package/lib/i18n/useComponentTranslations.js.map +1 -0
- package/lib/index.js +157 -0
- package/lib/locale/messages-en.js +439 -0
- package/lib/locale/messages-en.js.map +1 -0
- package/lib/locale/messages-nb.js +439 -0
- package/lib/locale/messages-nb.js.map +1 -0
- package/lib/locale/messages-nn.js +439 -0
- package/lib/locale/messages-nn.js.map +1 -0
- package/lib/locale/messages-se.js +439 -0
- package/lib/locale/messages-se.js.map +1 -0
- package/lib/model/ContentType.js +94 -0
- package/lib/model/ContentType.js.map +1 -0
- package/lib/model/SubjectCategories.js +30 -0
- package/lib/model/SubjectCategories.js.map +1 -0
- package/lib/model/SubjectTypes.js +28 -0
- package/lib/model/SubjectTypes.js.map +1 -0
- package/lib/model/WordClass.js +58 -0
- package/lib/model/WordClass.js.map +1 -0
- package/lib/model/index.js +19 -0
- package/lib/model/index.js.map +1 -0
- package/lib/utils/licenseAttributes.js +17 -0
- package/lib/utils/licenseAttributes.js.map +1 -0
- package/lib/utils/relativeUrl.js +26 -0
- package/lib/utils/relativeUrl.js.map +1 -0
- package/package.json +12 -11
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
import { useEffect, useRef, useState } from "react";
|
|
2
|
+
import { Button, FieldRoot, IconButton, PopoverContent, PopoverRoot, PopoverTrigger, SelectContent, SelectControl, SelectItem, SelectItemIndicator, SelectItemText, SelectLabel, SelectRoot, SelectTrigger, SliderControl, SliderHiddenInput, SliderLabel, SliderRange, SliderRoot, SliderThumb, SliderTrack, Text } from "@ndla/primitives";
|
|
3
|
+
import { styled } from "@ndla/styled-system/jsx";
|
|
4
|
+
import { useTranslation } from "react-i18next";
|
|
5
|
+
import { CheckLine, Forward15Line, PauseLine, PlayFill, Replay15Line, VolumeUpFill } from "@ndla/icons";
|
|
6
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
7
|
+
import { createListCollection } from "@ark-ui/react";
|
|
8
|
+
|
|
9
|
+
//#region src/AudioPlayer/Controls.tsx
|
|
10
|
+
const ControlsWrapper = styled("div", { base: {
|
|
11
|
+
borderBlockStart: "1px solid",
|
|
12
|
+
borderColor: "stroke.default",
|
|
13
|
+
borderBottomRadius: "xsmall",
|
|
14
|
+
display: "flex",
|
|
15
|
+
alignItems: "center",
|
|
16
|
+
justifyContent: "center",
|
|
17
|
+
background: "background.default",
|
|
18
|
+
gap: "xsmall",
|
|
19
|
+
paddingBlock: "xsmall",
|
|
20
|
+
paddingInline: "medium",
|
|
21
|
+
tabletWideDown: {
|
|
22
|
+
display: "grid",
|
|
23
|
+
paddingBlock: "xsmall",
|
|
24
|
+
paddingInline: "xsmall",
|
|
25
|
+
gridTemplateColumns: "1fr repeat(5, auto) 1fr",
|
|
26
|
+
gridTemplateAreas: `
|
|
27
|
+
"track track track track track track track"
|
|
28
|
+
". speed backwards play forwards volume ."
|
|
29
|
+
`
|
|
30
|
+
},
|
|
31
|
+
mobileWideDown: { columnGap: "3xsmall" }
|
|
32
|
+
} });
|
|
33
|
+
const PlayButton = styled(IconButton, { base: { gridArea: "play" } });
|
|
34
|
+
const Forward15SecButton = styled(IconButton, { base: { gridArea: "forwards" } });
|
|
35
|
+
const Back15SecButton = styled(IconButton, { base: { gridArea: "backwards" } });
|
|
36
|
+
const ProgressWrapper = styled("div", { base: {
|
|
37
|
+
flex: "1",
|
|
38
|
+
display: "flex",
|
|
39
|
+
alignItems: "center",
|
|
40
|
+
gap: "xxsmall",
|
|
41
|
+
gridArea: "track",
|
|
42
|
+
paddingBlock: "xsmall",
|
|
43
|
+
mobileDown: { paddingInline: "xsmall" }
|
|
44
|
+
} });
|
|
45
|
+
const StyledText = styled(Text, { base: {
|
|
46
|
+
minWidth: "xxlarge",
|
|
47
|
+
flexShrink: "0",
|
|
48
|
+
textAlign: "center"
|
|
49
|
+
} });
|
|
50
|
+
const VolumeButton = styled(IconButton, { base: { gridArea: "volume" } });
|
|
51
|
+
const SpeedButton = styled(Button, { base: {
|
|
52
|
+
paddingBlock: "auto",
|
|
53
|
+
paddingInline: "auto",
|
|
54
|
+
maxWidth: "xxlarge",
|
|
55
|
+
maxHeight: "xxlarge",
|
|
56
|
+
minWidth: "xxlarge",
|
|
57
|
+
minHeight: "xxlarge",
|
|
58
|
+
"& span": { flex: "1" }
|
|
59
|
+
} });
|
|
60
|
+
const StyledSelectRoot = styled(SelectRoot, { base: { gridArea: "speed" } });
|
|
61
|
+
const StyledSliderControl = styled(SliderControl, { base: {
|
|
62
|
+
height: "surface.3xsmall",
|
|
63
|
+
minWidth: "small"
|
|
64
|
+
} });
|
|
65
|
+
const StyledPopoverContent = styled(PopoverContent, { base: { paddingInline: "small" } });
|
|
66
|
+
const formatTime = (seconds) => {
|
|
67
|
+
const minutes = Math.floor(seconds / 60);
|
|
68
|
+
const currentSeconds = seconds % 60;
|
|
69
|
+
const formattedSeconds = currentSeconds < 10 ? `0${currentSeconds}` : currentSeconds;
|
|
70
|
+
return `${minutes}:${formattedSeconds}`;
|
|
71
|
+
};
|
|
72
|
+
const speedValues = createListCollection({ items: [
|
|
73
|
+
"0.5",
|
|
74
|
+
"0.75",
|
|
75
|
+
"1",
|
|
76
|
+
"1.25",
|
|
77
|
+
"1.5",
|
|
78
|
+
"1.75",
|
|
79
|
+
"2"
|
|
80
|
+
] });
|
|
81
|
+
const Controls = ({ src, title }) => {
|
|
82
|
+
const { t } = useTranslation();
|
|
83
|
+
const [speedValue, setSpeedValue] = useState(1);
|
|
84
|
+
const [volumeValue, setVolumeValue] = useState(100);
|
|
85
|
+
const [currentTime, setCurrentTime] = useState(0);
|
|
86
|
+
const [remainingTime, setRemainingTime] = useState(0);
|
|
87
|
+
const [playing, setPlaying] = useState(false);
|
|
88
|
+
const audioRef = useRef(null);
|
|
89
|
+
useEffect(() => {
|
|
90
|
+
if (audioRef.current) audioRef.current.playbackRate = speedValue;
|
|
91
|
+
}, [speedValue]);
|
|
92
|
+
useEffect(() => {
|
|
93
|
+
if (audioRef.current) {
|
|
94
|
+
const audioElement = audioRef.current;
|
|
95
|
+
const handleTimeUpdate = () => {
|
|
96
|
+
const { currentTime: currentTime$1, duration } = audioElement;
|
|
97
|
+
setCurrentTime(Math.round(currentTime$1));
|
|
98
|
+
setRemainingTime(Math.round(duration - currentTime$1));
|
|
99
|
+
};
|
|
100
|
+
const handleLoadedMetaData = () => {
|
|
101
|
+
const { currentTime: currentTime$1, duration } = audioElement;
|
|
102
|
+
setCurrentTime(Math.round(currentTime$1));
|
|
103
|
+
setRemainingTime(Math.round(duration - currentTime$1));
|
|
104
|
+
};
|
|
105
|
+
const handleTimeEnded = () => {
|
|
106
|
+
setPlaying(false);
|
|
107
|
+
};
|
|
108
|
+
audioElement.addEventListener("timeupdate", handleTimeUpdate);
|
|
109
|
+
audioElement.addEventListener("loadedmetadata", handleLoadedMetaData);
|
|
110
|
+
audioElement.addEventListener("ended", handleTimeEnded);
|
|
111
|
+
return () => {
|
|
112
|
+
audioElement.removeEventListener("timeupdate", handleTimeUpdate);
|
|
113
|
+
audioElement.removeEventListener("loadedmetadata", handleLoadedMetaData);
|
|
114
|
+
audioElement.removeEventListener("ended", handleTimeEnded);
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
}, []);
|
|
118
|
+
const togglePlay = () => {
|
|
119
|
+
if (audioRef.current) {
|
|
120
|
+
const audioElement = audioRef.current;
|
|
121
|
+
if (!playing) audioElement.play();
|
|
122
|
+
else audioElement.pause();
|
|
123
|
+
setPlaying(!playing);
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
const onSeekSeconds = (seconds) => {
|
|
127
|
+
if (audioRef.current) audioRef.current.currentTime += seconds;
|
|
128
|
+
};
|
|
129
|
+
const handleSliderChange = (details) => {
|
|
130
|
+
const newValue = details.value[0];
|
|
131
|
+
if (audioRef.current && newValue != null && !isNaN(newValue)) audioRef.current.currentTime = details.value[0];
|
|
132
|
+
};
|
|
133
|
+
const handleVolumeSliderChange = (details) => {
|
|
134
|
+
if (audioRef.current) {
|
|
135
|
+
audioRef.current.volume = details.value[0] / 100;
|
|
136
|
+
setVolumeValue(details.value[0]);
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
return /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("audio", {
|
|
140
|
+
ref: audioRef,
|
|
141
|
+
src,
|
|
142
|
+
title,
|
|
143
|
+
preload: "metadata"
|
|
144
|
+
}), /* @__PURE__ */ jsxs(ControlsWrapper, { children: [
|
|
145
|
+
/* @__PURE__ */ jsx(Back15SecButton, {
|
|
146
|
+
variant: "tertiary",
|
|
147
|
+
title: t("audio.controls.rewind15sec"),
|
|
148
|
+
"aria-label": t("audio.controls.rewind15sec"),
|
|
149
|
+
onClick: () => onSeekSeconds(-15),
|
|
150
|
+
children: /* @__PURE__ */ jsx(Replay15Line, {})
|
|
151
|
+
}),
|
|
152
|
+
/* @__PURE__ */ jsx(PlayButton, {
|
|
153
|
+
"aria-label": t(playing ? t("audio.pause") : t("audio.play")),
|
|
154
|
+
variant: "primary",
|
|
155
|
+
onClick: togglePlay,
|
|
156
|
+
children: playing ? /* @__PURE__ */ jsx(PauseLine, {}) : /* @__PURE__ */ jsx(PlayFill, {})
|
|
157
|
+
}),
|
|
158
|
+
/* @__PURE__ */ jsx(Forward15SecButton, {
|
|
159
|
+
variant: "tertiary",
|
|
160
|
+
title: t("audio.controls.forward15sec"),
|
|
161
|
+
"aria-label": t("audio.controls.forward15sec"),
|
|
162
|
+
onClick: () => onSeekSeconds(15),
|
|
163
|
+
children: /* @__PURE__ */ jsx(Forward15Line, {})
|
|
164
|
+
}),
|
|
165
|
+
/* @__PURE__ */ jsxs(ProgressWrapper, { children: [
|
|
166
|
+
/* @__PURE__ */ jsx(StyledText, {
|
|
167
|
+
textStyle: "label.medium",
|
|
168
|
+
asChild: true,
|
|
169
|
+
consumeCss: true,
|
|
170
|
+
children: /* @__PURE__ */ jsx("div", { children: formatTime(currentTime) })
|
|
171
|
+
}),
|
|
172
|
+
/* @__PURE__ */ jsxs(SliderRoot, {
|
|
173
|
+
value: [audioRef.current?.currentTime ?? 0],
|
|
174
|
+
defaultValue: [0],
|
|
175
|
+
step: 1,
|
|
176
|
+
max: Math.round(audioRef.current?.duration ?? 0),
|
|
177
|
+
onValueChange: handleSliderChange,
|
|
178
|
+
getAriaValueText: (value) => t("audio.valueText", {
|
|
179
|
+
start: formatTime(Math.round(value.value)),
|
|
180
|
+
end: formatTime(Math.round(audioRef.current?.duration ?? 0))
|
|
181
|
+
}),
|
|
182
|
+
children: [/* @__PURE__ */ jsx(SliderLabel, {
|
|
183
|
+
srOnly: true,
|
|
184
|
+
children: t("audio.progressBar")
|
|
185
|
+
}), /* @__PURE__ */ jsxs(SliderControl, { children: [/* @__PURE__ */ jsx(SliderTrack, { children: /* @__PURE__ */ jsx(SliderRange, {}) }), /* @__PURE__ */ jsx(SliderThumb, {
|
|
186
|
+
index: 0,
|
|
187
|
+
children: /* @__PURE__ */ jsx(SliderHiddenInput, {})
|
|
188
|
+
})] })]
|
|
189
|
+
}),
|
|
190
|
+
/* @__PURE__ */ jsx(StyledText, {
|
|
191
|
+
textStyle: "label.medium",
|
|
192
|
+
asChild: true,
|
|
193
|
+
consumeCss: true,
|
|
194
|
+
children: /* @__PURE__ */ jsxs("div", { children: ["-", formatTime(remainingTime)] })
|
|
195
|
+
})
|
|
196
|
+
] }),
|
|
197
|
+
/* @__PURE__ */ jsx(FieldRoot, { children: /* @__PURE__ */ jsxs(StyledSelectRoot, {
|
|
198
|
+
collection: speedValues,
|
|
199
|
+
value: [speedValue.toString()],
|
|
200
|
+
onValueChange: (details) => setSpeedValue(parseFloat(details.value[0])),
|
|
201
|
+
positioning: { placement: "top" },
|
|
202
|
+
children: [
|
|
203
|
+
/* @__PURE__ */ jsx(SelectLabel, {
|
|
204
|
+
srOnly: true,
|
|
205
|
+
children: t("audio.controls.selectSpeed")
|
|
206
|
+
}),
|
|
207
|
+
/* @__PURE__ */ jsx(SelectControl, { children: /* @__PURE__ */ jsx(SelectTrigger, {
|
|
208
|
+
asChild: true,
|
|
209
|
+
children: /* @__PURE__ */ jsx(SpeedButton, {
|
|
210
|
+
variant: "tertiary",
|
|
211
|
+
title: t("audio.controls.selectSpeed"),
|
|
212
|
+
"aria-label": t("audio.controls.selectSpeed"),
|
|
213
|
+
children: /* @__PURE__ */ jsx("span", { children: `${speedValue}x` })
|
|
214
|
+
})
|
|
215
|
+
}) }),
|
|
216
|
+
/* @__PURE__ */ jsx(SelectContent, { children: speedValues.items.map((speed) => /* @__PURE__ */ jsxs(SelectItem, {
|
|
217
|
+
item: speed,
|
|
218
|
+
children: [/* @__PURE__ */ jsxs(SelectItemText, { children: [speed, "x"] }), /* @__PURE__ */ jsx(SelectItemIndicator, { children: /* @__PURE__ */ jsx(CheckLine, {}) })]
|
|
219
|
+
}, speed)) })
|
|
220
|
+
]
|
|
221
|
+
}) }),
|
|
222
|
+
/* @__PURE__ */ jsxs(PopoverRoot, {
|
|
223
|
+
positioning: { placement: "top" },
|
|
224
|
+
children: [/* @__PURE__ */ jsx(PopoverTrigger, {
|
|
225
|
+
asChild: true,
|
|
226
|
+
children: /* @__PURE__ */ jsx(VolumeButton, {
|
|
227
|
+
variant: "tertiary",
|
|
228
|
+
"aria-label": t("audio.controls.adjustVolume"),
|
|
229
|
+
children: /* @__PURE__ */ jsx(VolumeUpFill, {})
|
|
230
|
+
})
|
|
231
|
+
}), /* @__PURE__ */ jsx(StyledPopoverContent, { children: /* @__PURE__ */ jsxs(SliderRoot, {
|
|
232
|
+
orientation: "vertical",
|
|
233
|
+
value: [volumeValue],
|
|
234
|
+
min: 0,
|
|
235
|
+
max: 100,
|
|
236
|
+
defaultValue: [100],
|
|
237
|
+
step: 1,
|
|
238
|
+
onValueChange: handleVolumeSliderChange,
|
|
239
|
+
children: [/* @__PURE__ */ jsx(SliderLabel, {
|
|
240
|
+
srOnly: true,
|
|
241
|
+
children: t("audio.controls.adjustVolume")
|
|
242
|
+
}), /* @__PURE__ */ jsxs(StyledSliderControl, { children: [/* @__PURE__ */ jsx(SliderTrack, { children: /* @__PURE__ */ jsx(SliderRange, {}) }), /* @__PURE__ */ jsx(SliderThumb, {
|
|
243
|
+
index: 0,
|
|
244
|
+
children: /* @__PURE__ */ jsx(SliderHiddenInput, {})
|
|
245
|
+
})] })]
|
|
246
|
+
}) })]
|
|
247
|
+
})
|
|
248
|
+
] })] });
|
|
249
|
+
};
|
|
250
|
+
var Controls_default = Controls;
|
|
251
|
+
|
|
252
|
+
//#endregion
|
|
253
|
+
export { Controls_default };
|
|
254
|
+
//# sourceMappingURL=Controls.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Controls.js","names":["seconds: number","currentTime","details: SliderValueChangeDetails"],"sources":["../../src/AudioPlayer/Controls.tsx"],"sourcesContent":["/**\n * Copyright (c) 2021-present, NDLA.\n *\n * This source code is licensed under the GPLv3 license found in the\n * LICENSE file in the root directory of this source tree.\n *\n */\n\nimport { useEffect, useRef, useState } from \"react\";\nimport { useTranslation } from \"react-i18next\";\nimport { type SliderValueChangeDetails, createListCollection } from \"@ark-ui/react\";\nimport { Replay15Line, Forward15Line, PlayFill, PauseLine, VolumeUpFill, CheckLine } from \"@ndla/icons\";\nimport {\n Button,\n FieldRoot,\n IconButton,\n PopoverContent,\n PopoverRoot,\n PopoverTrigger,\n SelectContent,\n SelectControl,\n SelectItem,\n SelectItemIndicator,\n SelectItemText,\n SelectLabel,\n SelectRoot,\n SelectTrigger,\n SliderControl,\n SliderHiddenInput,\n SliderLabel,\n SliderRange,\n SliderRoot,\n SliderThumb,\n SliderTrack,\n Text,\n} from \"@ndla/primitives\";\nimport { styled } from \"@ndla/styled-system/jsx\";\n\nconst ControlsWrapper = styled(\"div\", {\n base: {\n borderBlockStart: \"1px solid\",\n borderColor: \"stroke.default\",\n borderBottomRadius: \"xsmall\",\n display: \"flex\",\n alignItems: \"center\",\n justifyContent: \"center\",\n background: \"background.default\",\n gap: \"xsmall\",\n paddingBlock: \"xsmall\",\n paddingInline: \"medium\",\n tabletWideDown: {\n display: \"grid\",\n paddingBlock: \"xsmall\",\n paddingInline: \"xsmall\",\n gridTemplateColumns: \"1fr repeat(5, auto) 1fr\",\n gridTemplateAreas: `\n \"track track track track track track track\"\n \". speed backwards play forwards volume .\"\n`,\n },\n mobileWideDown: {\n columnGap: \"3xsmall\",\n },\n },\n});\n\nconst PlayButton = styled(IconButton, {\n base: {\n gridArea: \"play\",\n },\n});\n\nconst Forward15SecButton = styled(IconButton, {\n base: {\n gridArea: \"forwards\",\n },\n});\n\nconst Back15SecButton = styled(IconButton, {\n base: {\n gridArea: \"backwards\",\n },\n});\n\nconst ProgressWrapper = styled(\"div\", {\n base: {\n flex: \"1\",\n display: \"flex\",\n alignItems: \"center\",\n gap: \"xxsmall\",\n gridArea: \"track\",\n paddingBlock: \"xsmall\",\n mobileDown: {\n paddingInline: \"xsmall\",\n },\n },\n});\n\nconst StyledText = styled(Text, {\n base: {\n minWidth: \"xxlarge\",\n flexShrink: \"0\",\n textAlign: \"center\",\n },\n});\n\nconst VolumeButton = styled(IconButton, {\n base: {\n gridArea: \"volume\",\n },\n});\n\nconst SpeedButton = styled(Button, {\n base: {\n paddingBlock: \"auto\",\n paddingInline: \"auto\",\n maxWidth: \"xxlarge\",\n maxHeight: \"xxlarge\",\n minWidth: \"xxlarge\",\n minHeight: \"xxlarge\",\n \"& span\": {\n flex: \"1\",\n },\n },\n});\n\nconst StyledSelectRoot = styled(SelectRoot<string>, {\n base: {\n gridArea: \"speed\",\n },\n});\n\nconst StyledSliderControl = styled(SliderControl, {\n base: {\n height: \"surface.3xsmall\",\n minWidth: \"small\",\n },\n});\n\nconst StyledPopoverContent = styled(PopoverContent, {\n base: {\n paddingInline: \"small\",\n },\n});\n\nconst formatTime = (seconds: number) => {\n const minutes = Math.floor(seconds / 60);\n const currentSeconds = seconds % 60;\n\n const formattedSeconds = currentSeconds < 10 ? `0${currentSeconds}` : currentSeconds;\n return `${minutes}:${formattedSeconds}`;\n};\n\nconst speedValues = createListCollection({ items: [\"0.5\", \"0.75\", \"1\", \"1.25\", \"1.5\", \"1.75\", \"2\"] });\n\ninterface Props {\n src: string;\n title: string;\n}\n\nconst Controls = ({ src, title }: Props) => {\n const { t } = useTranslation();\n const [speedValue, setSpeedValue] = useState(1);\n const [volumeValue, setVolumeValue] = useState(100);\n const [currentTime, setCurrentTime] = useState(0);\n const [remainingTime, setRemainingTime] = useState(0);\n const [playing, setPlaying] = useState(false);\n const audioRef = useRef<HTMLAudioElement>(null);\n\n useEffect(() => {\n if (audioRef.current) {\n audioRef.current.playbackRate = speedValue;\n }\n }, [speedValue]);\n\n useEffect(() => {\n if (audioRef.current) {\n const audioElement = audioRef.current;\n const handleTimeUpdate = () => {\n const { currentTime, duration } = audioElement;\n setCurrentTime(Math.round(currentTime));\n setRemainingTime(Math.round(duration - currentTime));\n };\n\n const handleLoadedMetaData = () => {\n const { currentTime, duration } = audioElement;\n setCurrentTime(Math.round(currentTime));\n setRemainingTime(Math.round(duration - currentTime));\n };\n\n const handleTimeEnded = () => {\n setPlaying(false);\n };\n\n audioElement.addEventListener(\"timeupdate\", handleTimeUpdate);\n audioElement.addEventListener(\"loadedmetadata\", handleLoadedMetaData);\n audioElement.addEventListener(\"ended\", handleTimeEnded);\n return () => {\n audioElement.removeEventListener(\"timeupdate\", handleTimeUpdate);\n audioElement.removeEventListener(\"loadedmetadata\", handleLoadedMetaData);\n audioElement.removeEventListener(\"ended\", handleTimeEnded);\n };\n }\n }, []);\n\n const togglePlay = () => {\n if (audioRef.current) {\n const audioElement = audioRef.current;\n if (!playing) {\n audioElement.play();\n } else {\n audioElement.pause();\n }\n setPlaying(!playing);\n }\n };\n\n const onSeekSeconds = (seconds: number) => {\n if (audioRef.current) {\n audioRef.current.currentTime += seconds;\n }\n };\n\n const handleSliderChange = (details: SliderValueChangeDetails) => {\n const newValue = details.value[0];\n if (audioRef.current && newValue != null && !isNaN(newValue)) {\n audioRef.current.currentTime = details.value[0];\n }\n };\n\n const handleVolumeSliderChange = (details: SliderValueChangeDetails) => {\n if (audioRef.current) {\n audioRef.current.volume = details.value[0] / 100;\n setVolumeValue(details.value[0]);\n }\n };\n\n return (\n <div>\n {/* TODO: We should tie this up to the textual description somehow */}\n {/* eslint-disable-next-line jsx-a11y/media-has-caption */}\n <audio ref={audioRef} src={src} title={title} preload=\"metadata\" />\n <ControlsWrapper>\n <Back15SecButton\n variant=\"tertiary\"\n title={t(\"audio.controls.rewind15sec\")}\n aria-label={t(\"audio.controls.rewind15sec\")}\n onClick={() => onSeekSeconds(-15)}\n >\n <Replay15Line />\n </Back15SecButton>\n <PlayButton aria-label={t(playing ? t(\"audio.pause\") : t(\"audio.play\"))} variant=\"primary\" onClick={togglePlay}>\n {playing ? <PauseLine /> : <PlayFill />}\n </PlayButton>\n <Forward15SecButton\n variant=\"tertiary\"\n title={t(\"audio.controls.forward15sec\")}\n aria-label={t(\"audio.controls.forward15sec\")}\n onClick={() => onSeekSeconds(15)}\n >\n <Forward15Line />\n </Forward15SecButton>\n <ProgressWrapper>\n <StyledText textStyle=\"label.medium\" asChild consumeCss>\n <div>{formatTime(currentTime)}</div>\n </StyledText>\n <SliderRoot\n value={[audioRef.current?.currentTime ?? 0]}\n defaultValue={[0]}\n step={1}\n max={Math.round(audioRef.current?.duration ?? 0)}\n onValueChange={handleSliderChange}\n getAriaValueText={(value) =>\n t(\"audio.valueText\", {\n start: formatTime(Math.round(value.value)),\n end: formatTime(Math.round(audioRef.current?.duration ?? 0)),\n })\n }\n >\n <SliderLabel srOnly>{t(\"audio.progressBar\")}</SliderLabel>\n <SliderControl>\n <SliderTrack>\n <SliderRange />\n </SliderTrack>\n <SliderThumb index={0}>\n <SliderHiddenInput />\n </SliderThumb>\n </SliderControl>\n </SliderRoot>\n <StyledText textStyle=\"label.medium\" asChild consumeCss>\n <div>-{formatTime(remainingTime)}</div>\n </StyledText>\n </ProgressWrapper>\n <FieldRoot>\n <StyledSelectRoot\n collection={speedValues}\n value={[speedValue.toString()]}\n onValueChange={(details) => setSpeedValue(parseFloat(details.value[0]))}\n positioning={{ placement: \"top\" }}\n >\n <SelectLabel srOnly>{t(\"audio.controls.selectSpeed\")}</SelectLabel>\n <SelectControl>\n <SelectTrigger asChild>\n <SpeedButton\n variant=\"tertiary\"\n title={t(\"audio.controls.selectSpeed\")}\n aria-label={t(\"audio.controls.selectSpeed\")}\n >\n <span>{`${speedValue}x`}</span>\n </SpeedButton>\n </SelectTrigger>\n </SelectControl>\n <SelectContent>\n {speedValues.items.map((speed) => (\n <SelectItem key={speed} item={speed}>\n <SelectItemText>{speed}x</SelectItemText>\n <SelectItemIndicator>\n <CheckLine />\n </SelectItemIndicator>\n </SelectItem>\n ))}\n </SelectContent>\n </StyledSelectRoot>\n </FieldRoot>\n <PopoverRoot positioning={{ placement: \"top\" }}>\n <PopoverTrigger asChild>\n <VolumeButton variant=\"tertiary\" aria-label={t(\"audio.controls.adjustVolume\")}>\n <VolumeUpFill />\n </VolumeButton>\n </PopoverTrigger>\n <StyledPopoverContent>\n <SliderRoot\n orientation=\"vertical\"\n value={[volumeValue]}\n min={0}\n max={100}\n defaultValue={[100]}\n step={1}\n onValueChange={handleVolumeSliderChange}\n >\n <SliderLabel srOnly>{t(\"audio.controls.adjustVolume\")}</SliderLabel>\n <StyledSliderControl>\n <SliderTrack>\n <SliderRange />\n </SliderTrack>\n <SliderThumb index={0}>\n <SliderHiddenInput />\n </SliderThumb>\n </StyledSliderControl>\n </SliderRoot>\n </StyledPopoverContent>\n </PopoverRoot>\n </ControlsWrapper>\n </div>\n );\n};\n\nexport default Controls;\n"],"mappings":"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"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { useRef } from "react";
|
|
2
|
+
import { IconButton, TooltipContent, TooltipRoot, TooltipTrigger } from "@ndla/primitives";
|
|
3
|
+
import { useTranslation } from "react-i18next";
|
|
4
|
+
import { VolumeUpFill } from "@ndla/icons";
|
|
5
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
6
|
+
|
|
7
|
+
//#region src/AudioPlayer/SpeechControl.tsx
|
|
8
|
+
const SpeechControl = ({ src, title, type = "audio" }) => {
|
|
9
|
+
const { t } = useTranslation();
|
|
10
|
+
const audioRef = useRef(null);
|
|
11
|
+
const togglePlay = () => {
|
|
12
|
+
if (audioRef.current) {
|
|
13
|
+
const audioElement = audioRef.current;
|
|
14
|
+
if (audioElement.paused) audioElement.play();
|
|
15
|
+
else audioElement.pause();
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
19
|
+
"data-embed-type": "speech",
|
|
20
|
+
children: [/* @__PURE__ */ jsx("audio", {
|
|
21
|
+
ref: audioRef,
|
|
22
|
+
src,
|
|
23
|
+
title,
|
|
24
|
+
preload: "metadata"
|
|
25
|
+
}), /* @__PURE__ */ jsxs(TooltipRoot, { children: [/* @__PURE__ */ jsx(TooltipTrigger, {
|
|
26
|
+
asChild: true,
|
|
27
|
+
children: /* @__PURE__ */ jsx(IconButton, {
|
|
28
|
+
variant: "tertiary",
|
|
29
|
+
"aria-label": t(`${type}.play`),
|
|
30
|
+
onClick: togglePlay,
|
|
31
|
+
children: /* @__PURE__ */ jsx(VolumeUpFill, {})
|
|
32
|
+
})
|
|
33
|
+
}), /* @__PURE__ */ jsx(TooltipContent, { children: t(`${type}.play`) })] })]
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
var SpeechControl_default = SpeechControl;
|
|
37
|
+
|
|
38
|
+
//#endregion
|
|
39
|
+
export { SpeechControl_default };
|
|
40
|
+
//# sourceMappingURL=SpeechControl.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SpeechControl.js","names":[],"sources":["../../src/AudioPlayer/SpeechControl.tsx"],"sourcesContent":["/**\n * Copyright (c) 2021-present, NDLA.\n *\n * This source code is licensed under the GPLv3 license found in the\n * LICENSE file in the root directory of this source tree.\n *\n */\n\nimport { useRef } from \"react\";\nimport { useTranslation } from \"react-i18next\";\nimport { VolumeUpFill } from \"@ndla/icons\";\nimport { TooltipRoot, TooltipTrigger, TooltipContent, IconButton } from \"@ndla/primitives\";\n\ntype Props = {\n src: string;\n title: string;\n type?: \"gloss\" | \"audio\";\n};\n\nconst SpeechControl = ({ src, title, type = \"audio\" }: Props) => {\n const { t } = useTranslation();\n const audioRef = useRef<HTMLAudioElement>(null);\n\n const togglePlay = () => {\n if (audioRef.current) {\n const audioElement = audioRef.current;\n if (audioElement.paused) {\n audioElement.play();\n } else {\n audioElement.pause();\n }\n }\n };\n return (\n <div data-embed-type=\"speech\">\n {/* eslint-disable-next-line jsx-a11y/media-has-caption */}\n <audio ref={audioRef} src={src} title={title} preload=\"metadata\" />\n <TooltipRoot>\n <TooltipTrigger asChild>\n <IconButton variant=\"tertiary\" aria-label={t(`${type}.play`)} onClick={togglePlay}>\n <VolumeUpFill />\n </IconButton>\n </TooltipTrigger>\n <TooltipContent>{t(`${type}.play`)}</TooltipContent>\n </TooltipRoot>\n </div>\n );\n};\n\nexport default SpeechControl;\n"],"mappings":";;;;;;;AAmBA,MAAM,gBAAgB,CAAC,EAAE,KAAK,OAAO,OAAO,SAAgB,KAAK;CAC/D,MAAM,EAAE,GAAG,GAAG,gBAAgB;CAC9B,MAAM,WAAW,OAAyB,KAAK;CAE/C,MAAM,aAAa,MAAM;AACvB,MAAI,SAAS,SAAS;GACpB,MAAM,eAAe,SAAS;AAC9B,OAAI,aAAa,OACf,cAAa,MAAM;OAEnB,cAAa,OAAO;EAEvB;CACF;AACD,wBACE,KAAC;EAAI,mBAAgB;6BAEnB,IAAC;GAAM,KAAK;GAAe;GAAY;GAAO,SAAQ;IAAa,kBACnE,KAAC,0CACC,IAAC;GAAe;6BACd,IAAC;IAAW,SAAQ;IAAW,cAAY,GAAG,EAAE,KAAK,OAAO;IAAE,SAAS;8BACrE,IAAC,iBAAe;KACL;IACE,kBACjB,IAAC,4BAAgB,GAAG,EAAE,KAAK,OAAO,GAAkB,IACxC;GACV;AAET;AAED,4BAAe"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["AudioPlayer"],"sources":["../../src/AudioPlayer/index.ts"],"sourcesContent":["/**\n * Copyright (c) 2021-present, NDLA.\n *\n * This source code is licensed under the GPLv3 license found in the\n * LICENSE file in the root directory of this source tree.\n *\n */\n\nimport AudioPlayer from \"./AudioPlayer\";\n\nexport default AudioPlayer;\n"],"mappings":";;;AAUA,4BAAeA"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { BreadcrumbItem_default } from "./BreadcrumbItem.js";
|
|
2
|
+
import "react";
|
|
3
|
+
import { styled } from "@ndla/styled-system/jsx";
|
|
4
|
+
import { useTranslation } from "react-i18next";
|
|
5
|
+
import { jsx } from "react/jsx-runtime";
|
|
6
|
+
|
|
7
|
+
//#region src/Breadcrumb/Breadcrumb.tsx
|
|
8
|
+
const StyledList = styled("ol", { base: {
|
|
9
|
+
display: "flex",
|
|
10
|
+
flexWrap: "wrap",
|
|
11
|
+
alignItems: "center",
|
|
12
|
+
listStyle: "none",
|
|
13
|
+
gap: "xxsmall",
|
|
14
|
+
mobileDown: {
|
|
15
|
+
alignItems: "flex-start",
|
|
16
|
+
justifyContent: "center",
|
|
17
|
+
flexDirection: "column"
|
|
18
|
+
}
|
|
19
|
+
} });
|
|
20
|
+
const Breadcrumb = ({ items, renderItem, renderSeparator, collapseFirst, collapseLast = true }) => {
|
|
21
|
+
const { t } = useTranslation();
|
|
22
|
+
return /* @__PURE__ */ jsx("nav", {
|
|
23
|
+
"aria-label": t("breadcrumb.breadcrumb"),
|
|
24
|
+
children: /* @__PURE__ */ jsx(StyledList, { children: items.map((item, index) => /* @__PURE__ */ jsx(BreadcrumbItem_default, {
|
|
25
|
+
renderItem,
|
|
26
|
+
renderSeparator,
|
|
27
|
+
ref: (element) => {
|
|
28
|
+
if (element === null || !collapseFirst && index === 0 || !collapseLast && index === items.length - 1) {
|
|
29
|
+
if (element) element.setMaxWidth("none");
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
totalCount: items.length,
|
|
33
|
+
item: {
|
|
34
|
+
...item,
|
|
35
|
+
index
|
|
36
|
+
}
|
|
37
|
+
}, typeof item.to === "string" ? item.to : item.to.pathname)) })
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
var Breadcrumb_default = Breadcrumb;
|
|
41
|
+
|
|
42
|
+
//#endregion
|
|
43
|
+
export { Breadcrumb_default };
|
|
44
|
+
//# sourceMappingURL=Breadcrumb.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Breadcrumb.js","names":["BreadcrumbItem"],"sources":["../../src/Breadcrumb/Breadcrumb.tsx"],"sourcesContent":["/**\n * Copyright (c) 2016-present, NDLA.\n *\n * This source code is licensed under the GPLv3 license found in the\n * LICENSE file in the root directory of this source tree.\n *\n */\n\nimport { type ReactNode } from \"react\";\nimport { useTranslation } from \"react-i18next\";\nimport { styled } from \"@ndla/styled-system/jsx\";\nimport BreadcrumbItem, { type IndexedBreadcrumbItem, type SimpleBreadcrumbItem } from \"./BreadcrumbItem\";\n\ninterface Props {\n items: SimpleBreadcrumbItem[];\n collapseFirst?: boolean;\n collapseLast?: boolean;\n renderItem?: (item: IndexedBreadcrumbItem, totalCount: number) => ReactNode;\n renderSeparator?: (item: IndexedBreadcrumbItem, totalCount: number) => ReactNode;\n}\n\nconst StyledList = styled(\"ol\", {\n base: {\n display: \"flex\",\n flexWrap: \"wrap\",\n alignItems: \"center\",\n listStyle: \"none\",\n gap: \"xxsmall\",\n mobileDown: {\n alignItems: \"flex-start\",\n justifyContent: \"center\",\n flexDirection: \"column\",\n },\n },\n});\n\nconst Breadcrumb = ({ items, renderItem, renderSeparator, collapseFirst, collapseLast = true }: Props) => {\n const { t } = useTranslation();\n\n return (\n <nav aria-label={t(\"breadcrumb.breadcrumb\")}>\n <StyledList>\n {items.map((item, index) => (\n <BreadcrumbItem\n renderItem={renderItem}\n renderSeparator={renderSeparator}\n ref={(element) => {\n if (\n element === null ||\n (!collapseFirst && index === 0) ||\n (!collapseLast && index === items.length - 1)\n ) {\n if (element) {\n element.setMaxWidth(\"none\");\n }\n }\n }}\n key={typeof item.to === \"string\" ? item.to : item.to.pathname}\n totalCount={items.length}\n item={{ ...item, index }}\n />\n ))}\n </StyledList>\n </nav>\n );\n};\n\nexport default Breadcrumb;\n"],"mappings":";;;;;;;AAqBA,MAAM,aAAa,OAAO,MAAM,EAC9B,MAAM;CACJ,SAAS;CACT,UAAU;CACV,YAAY;CACZ,WAAW;CACX,KAAK;CACL,YAAY;EACV,YAAY;EACZ,gBAAgB;EAChB,eAAe;CAChB;AACF,EACF,EAAC;AAEF,MAAM,aAAa,CAAC,EAAE,OAAO,YAAY,iBAAiB,eAAe,eAAe,MAAa,KAAK;CACxG,MAAM,EAAE,GAAG,GAAG,gBAAgB;AAE9B,wBACE,IAAC;EAAI,cAAY,EAAE,wBAAwB;4BACzC,IAAC,wBACE,MAAM,IAAI,CAAC,MAAM,0BAChB,IAACA;GACa;GACK;GACjB,KAAK,CAAC,YAAY;AAChB,QACE,YAAY,SACV,iBAAiB,UAAU,MAC3B,gBAAgB,UAAU,MAAM,SAAS,GAE3C;SAAI,QACF,SAAQ,YAAY,OAAO;IAC5B;GAEJ;GAED,YAAY,MAAM;GAClB,MAAM;IAAE,GAAG;IAAM;GAAO;YAFZ,KAAK,OAAO,WAAW,KAAK,KAAK,KAAK,GAAG,SAGrD,CACF,GACS;GACT;AAET;AAED,yBAAe"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { forwardRef, useImperativeHandle, useRef } from "react";
|
|
2
|
+
import { styled } from "@ndla/styled-system/jsx";
|
|
3
|
+
import { ArrowRightShortLine } from "@ndla/icons";
|
|
4
|
+
import { SafeLink } from "@ndla/safelink";
|
|
5
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
6
|
+
|
|
7
|
+
//#region src/Breadcrumb/BreadcrumbItem.tsx
|
|
8
|
+
const StyledListItem = styled("li", { base: {
|
|
9
|
+
display: "flex",
|
|
10
|
+
color: "inherit",
|
|
11
|
+
gap: "3xsmall",
|
|
12
|
+
alignItems: "flex-end",
|
|
13
|
+
tabletDown: { display: "block" },
|
|
14
|
+
"& a": { _visited: { color: "inherit" } }
|
|
15
|
+
} });
|
|
16
|
+
const BreadcrumbItem = forwardRef(({ renderItem, renderSeparator, item, totalCount }, ref) => {
|
|
17
|
+
const liRef = useRef(null);
|
|
18
|
+
useImperativeHandle(ref, () => ({ setMaxWidth: (maxWidth) => {
|
|
19
|
+
liRef.current.children[0].style.maxWidth = maxWidth;
|
|
20
|
+
} }));
|
|
21
|
+
const { to, name, index } = item;
|
|
22
|
+
const isLast = index === totalCount - 1;
|
|
23
|
+
return /* @__PURE__ */ jsxs(StyledListItem, {
|
|
24
|
+
ref: liRef,
|
|
25
|
+
"aria-current": isLast ? "page" : void 0,
|
|
26
|
+
children: [renderItem ? renderItem(item, totalCount) : isLast ? /* @__PURE__ */ jsx("span", { children: name }) : /* @__PURE__ */ jsx(SafeLink, {
|
|
27
|
+
to,
|
|
28
|
+
children: /* @__PURE__ */ jsx("span", { children: name })
|
|
29
|
+
}), renderSeparator ? renderSeparator(item, totalCount) : !isLast && /* @__PURE__ */ jsx(ArrowRightShortLine, {})]
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
var BreadcrumbItem_default = BreadcrumbItem;
|
|
33
|
+
|
|
34
|
+
//#endregion
|
|
35
|
+
export { BreadcrumbItem_default };
|
|
36
|
+
//# sourceMappingURL=BreadcrumbItem.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BreadcrumbItem.js","names":["maxWidth: number"],"sources":["../../src/Breadcrumb/BreadcrumbItem.tsx"],"sourcesContent":["/**\n * Copyright (c) 2016-present, NDLA.\n *\n * This source code is licensed under the GPLv3 license found in the\n * LICENSE file in the root directory of this source tree.\n *\n */\n\nimport { useRef, useImperativeHandle, type ReactNode, forwardRef } from \"react\";\nimport { ArrowRightShortLine } from \"@ndla/icons\";\nimport { SafeLink } from \"@ndla/safelink\";\nimport { styled } from \"@ndla/styled-system/jsx\";\n\nexport interface SimpleBreadcrumbItem {\n to: string | Partial<Location>;\n name: ReactNode;\n}\n\nexport interface IndexedBreadcrumbItem extends SimpleBreadcrumbItem {\n index: number;\n}\n\nexport interface BreadcrumbRenderProps {\n item: IndexedBreadcrumbItem;\n totalCount: number;\n}\n\nconst StyledListItem = styled(\"li\", {\n base: {\n display: \"flex\",\n color: \"inherit\",\n gap: \"3xsmall\",\n alignItems: \"flex-end\",\n tabletDown: {\n display: \"block\",\n },\n \"& a\": {\n _visited: {\n color: \"inherit\",\n },\n },\n },\n});\n\ninterface Props {\n item: IndexedBreadcrumbItem;\n autoCollapse?: boolean;\n totalCount: number;\n renderItem?: (item: IndexedBreadcrumbItem, totalCount: number) => ReactNode;\n renderSeparator?: (item: IndexedBreadcrumbItem, totalCount: number) => ReactNode;\n}\n\nconst BreadcrumbItem = forwardRef<any, Props>(({ renderItem, renderSeparator, item, totalCount }, ref) => {\n const liRef = useRef<any>(null);\n\n useImperativeHandle(ref, () => ({\n setMaxWidth: (maxWidth: number) => {\n liRef.current.children[0].style.maxWidth = maxWidth;\n },\n }));\n\n const { to, name, index } = item;\n const isLast = index === totalCount - 1;\n return (\n <StyledListItem ref={liRef} aria-current={isLast ? \"page\" : undefined}>\n {renderItem ? (\n renderItem(item, totalCount)\n ) : isLast ? (\n <span>{name}</span>\n ) : (\n <SafeLink to={to}>\n <span>{name}</span>\n </SafeLink>\n )}\n {renderSeparator ? renderSeparator(item, totalCount) : !isLast && <ArrowRightShortLine />}\n </StyledListItem>\n );\n});\n\nexport default BreadcrumbItem;\n"],"mappings":";;;;;;;AA2BA,MAAM,iBAAiB,OAAO,MAAM,EAClC,MAAM;CACJ,SAAS;CACT,OAAO;CACP,KAAK;CACL,YAAY;CACZ,YAAY,EACV,SAAS,QACV;CACD,OAAO,EACL,UAAU,EACR,OAAO,UACR,EACF;AACF,EACF,EAAC;AAUF,MAAM,iBAAiB,WAAuB,CAAC,EAAE,YAAY,iBAAiB,MAAM,YAAY,EAAE,QAAQ;CACxG,MAAM,QAAQ,OAAY,KAAK;AAE/B,qBAAoB,KAAK,OAAO,EAC9B,aAAa,CAACA,aAAqB;AACjC,QAAM,QAAQ,SAAS,GAAG,MAAM,WAAW;CAC5C,EACF,GAAE;CAEH,MAAM,EAAE,IAAI,MAAM,OAAO,GAAG;CAC5B,MAAM,SAAS,UAAU,aAAa;AACtC,wBACE,KAAC;EAAe,KAAK;EAAO,gBAAc,SAAS;aAChD,aACC,WAAW,MAAM,WAAW,GAC1B,yBACF,IAAC,oBAAM,OAAY,mBAEnB,IAAC;GAAa;6BACZ,IAAC,oBAAM,OAAY;IACV,EAEZ,kBAAkB,gBAAgB,MAAM,WAAW,IAAI,0BAAU,IAAC,wBAAsB;GAC1E;AAEpB,EAAC;AAEF,6BAAe"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { Breadcrumb_default } from "./Breadcrumb.js";
|
|
2
|
+
import { styled } from "@ndla/styled-system/jsx";
|
|
3
|
+
import { ArrowRightShortLine, HomeLine } from "@ndla/icons";
|
|
4
|
+
import { SafeLink } from "@ndla/safelink";
|
|
5
|
+
import { jsx } from "react/jsx-runtime";
|
|
6
|
+
|
|
7
|
+
//#region src/Breadcrumb/HomeBreadcrumb.tsx
|
|
8
|
+
const StyledSafeLink = styled(SafeLink, { base: {
|
|
9
|
+
color: "inherit",
|
|
10
|
+
textDecoration: "underline",
|
|
11
|
+
_hover: { textDecoration: "none" },
|
|
12
|
+
_focusVisible: { textDecoration: "none" }
|
|
13
|
+
} });
|
|
14
|
+
const StyledArrowRight = styled(ArrowRightShortLine, { base: { tabletDown: { display: "none" } } });
|
|
15
|
+
const IconSafeLink = styled(SafeLink, { base: { color: "inherit" } });
|
|
16
|
+
const HomeBreadcrumb = ({ items }) => {
|
|
17
|
+
const renderItem = (item, totalCount) => {
|
|
18
|
+
if (item.index === totalCount - 1) return /* @__PURE__ */ jsx("span", { children: item.name });
|
|
19
|
+
if (item.index === 0 && typeof item.name === "string") return /* @__PURE__ */ jsx(IconSafeLink, {
|
|
20
|
+
"aria-label": item.name,
|
|
21
|
+
to: item.to,
|
|
22
|
+
children: /* @__PURE__ */ jsx(HomeLine, { title: item.name })
|
|
23
|
+
});
|
|
24
|
+
return /* @__PURE__ */ jsx(StyledSafeLink, {
|
|
25
|
+
to: item.to,
|
|
26
|
+
children: item.name
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
const renderSeparator = (item, totalCount) => {
|
|
30
|
+
if (item.index === totalCount - 1) return null;
|
|
31
|
+
if (item.index === 0) return /* @__PURE__ */ jsx(StyledArrowRight, {});
|
|
32
|
+
return /* @__PURE__ */ jsx(ArrowRightShortLine, {});
|
|
33
|
+
};
|
|
34
|
+
return /* @__PURE__ */ jsx(Breadcrumb_default, {
|
|
35
|
+
items,
|
|
36
|
+
renderItem,
|
|
37
|
+
renderSeparator
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
var HomeBreadcrumb_default = HomeBreadcrumb;
|
|
41
|
+
|
|
42
|
+
//#endregion
|
|
43
|
+
export { HomeBreadcrumb_default };
|
|
44
|
+
//# sourceMappingURL=HomeBreadcrumb.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HomeBreadcrumb.js","names":["item: IndexedBreadcrumbItem","totalCount: number","Breadcrumb"],"sources":["../../src/Breadcrumb/HomeBreadcrumb.tsx"],"sourcesContent":["/**\n * Copyright (c) 2022-present, NDLA.\n *\n * This source code is licensed under the GPLv3 license found in the\n * LICENSE file in the root directory of this source tree.\n *\n */\n\nimport { ArrowRightShortLine, HomeLine } from \"@ndla/icons\";\nimport { SafeLink } from \"@ndla/safelink\";\nimport { styled } from \"@ndla/styled-system/jsx\";\nimport Breadcrumb from \"./Breadcrumb\";\nimport type { IndexedBreadcrumbItem, SimpleBreadcrumbItem } from \"./BreadcrumbItem\";\n\nconst StyledSafeLink = styled(SafeLink, {\n base: {\n color: \"inherit\",\n textDecoration: \"underline\",\n _hover: {\n textDecoration: \"none\",\n },\n _focusVisible: {\n textDecoration: \"none\",\n },\n },\n});\n\nconst StyledArrowRight = styled(ArrowRightShortLine, {\n base: {\n tabletDown: {\n display: \"none\",\n },\n },\n});\n\nconst IconSafeLink = styled(SafeLink, {\n base: {\n color: \"inherit\",\n },\n});\n\ninterface Props {\n items: SimpleBreadcrumbItem[];\n}\n\nconst HomeBreadcrumb = ({ items }: Props) => {\n const renderItem = (item: IndexedBreadcrumbItem, totalCount: number) => {\n if (item.index === totalCount - 1) {\n return <span>{item.name}</span>;\n }\n if (item.index === 0 && typeof item.name === \"string\") {\n return (\n <IconSafeLink aria-label={item.name} to={item.to}>\n <HomeLine title={item.name} />\n </IconSafeLink>\n );\n }\n return <StyledSafeLink to={item.to}>{item.name}</StyledSafeLink>;\n };\n\n const renderSeparator = (item: IndexedBreadcrumbItem, totalCount: number) => {\n if (item.index === totalCount - 1) {\n return null;\n }\n if (item.index === 0) {\n return <StyledArrowRight />;\n }\n return <ArrowRightShortLine />;\n };\n\n return <Breadcrumb items={items} renderItem={renderItem} renderSeparator={renderSeparator} />;\n};\n\nexport default HomeBreadcrumb;\n"],"mappings":";;;;;;;AAcA,MAAM,iBAAiB,OAAO,UAAU,EACtC,MAAM;CACJ,OAAO;CACP,gBAAgB;CAChB,QAAQ,EACN,gBAAgB,OACjB;CACD,eAAe,EACb,gBAAgB,OACjB;AACF,EACF,EAAC;AAEF,MAAM,mBAAmB,OAAO,qBAAqB,EACnD,MAAM,EACJ,YAAY,EACV,SAAS,OACV,EACF,EACF,EAAC;AAEF,MAAM,eAAe,OAAO,UAAU,EACpC,MAAM,EACJ,OAAO,UACR,EACF,EAAC;AAMF,MAAM,iBAAiB,CAAC,EAAE,OAAc,KAAK;CAC3C,MAAM,aAAa,CAACA,MAA6BC,eAAuB;AACtE,MAAI,KAAK,UAAU,aAAa,EAC9B,wBAAO,IAAC,oBAAM,KAAK,OAAY;AAEjC,MAAI,KAAK,UAAU,YAAY,KAAK,SAAS,SAC3C,wBACE,IAAC;GAAa,cAAY,KAAK;GAAM,IAAI,KAAK;6BAC5C,IAAC,YAAS,OAAO,KAAK,OAAQ;IACjB;AAGnB,yBAAO,IAAC;GAAe,IAAI,KAAK;aAAK,KAAK;IAAsB;CACjE;CAED,MAAM,kBAAkB,CAACD,MAA6BC,eAAuB;AAC3E,MAAI,KAAK,UAAU,aAAa,EAC9B,QAAO;AAET,MAAI,KAAK,UAAU,EACjB,wBAAO,IAAC,qBAAmB;AAE7B,yBAAO,IAAC,wBAAsB;CAC/B;AAED,wBAAO,IAACC;EAAkB;EAAmB;EAA6B;GAAmB;AAC9F;AAED,6BAAe"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Breadcrumb_default } from "./Breadcrumb.js";
|
|
2
|
+
import { HomeBreadcrumb_default } from "./HomeBreadcrumb.js";
|
|
3
|
+
|
|
4
|
+
//#region src/Breadcrumb/index.ts
|
|
5
|
+
var Breadcrumb_default$1 = Breadcrumb_default;
|
|
6
|
+
|
|
7
|
+
//#endregion
|
|
8
|
+
export { Breadcrumb_default$1 as Breadcrumb_default };
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["Breadcrumb"],"sources":["../../src/Breadcrumb/index.ts"],"sourcesContent":["/**\n * Copyright (c) 2016-present, NDLA.\n *\n * This source code is licensed under the GPLv3 license found in the\n * LICENSE file in the root directory of this source tree.\n *\n */\n\nimport Breadcrumb from \"./Breadcrumb\";\n\nexport type { SimpleBreadcrumbItem, IndexedBreadcrumbItem } from \"./BreadcrumbItem\";\n\nexport { default as HomeBreadcrumb } from \"./HomeBreadcrumb\";\n\nexport default Breadcrumb;\n"],"mappings":";;;;AAcA,2BAAeA"}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { getPossiblyRelativeUrl } from "../utils/relativeUrl.js";
|
|
2
|
+
import "react";
|
|
3
|
+
import { Text } from "@ndla/primitives";
|
|
4
|
+
import { styled } from "@ndla/styled-system/jsx";
|
|
5
|
+
import parse from "html-react-parser";
|
|
6
|
+
import { ArrowRightLine } from "@ndla/icons";
|
|
7
|
+
import { SafeLinkButton } from "@ndla/safelink";
|
|
8
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
9
|
+
|
|
10
|
+
//#region src/CampaignBlock/CampaignBlock.tsx
|
|
11
|
+
const Wrapper = styled("div", { base: {
|
|
12
|
+
width: "100%",
|
|
13
|
+
height: "100%",
|
|
14
|
+
containerType: "inline-size"
|
|
15
|
+
} });
|
|
16
|
+
const Container = styled("div", {
|
|
17
|
+
base: {
|
|
18
|
+
display: "grid",
|
|
19
|
+
gridTemplateColumns: "1fr",
|
|
20
|
+
border: "1px solid",
|
|
21
|
+
borderColor: "stroke.default",
|
|
22
|
+
backgroundColor: "background.default",
|
|
23
|
+
borderRadius: "xsmall",
|
|
24
|
+
boxShadow: "full",
|
|
25
|
+
overflow: "hidden"
|
|
26
|
+
},
|
|
27
|
+
variants: {
|
|
28
|
+
imageSide: {
|
|
29
|
+
left: {
|
|
30
|
+
"@/tablet": { gridTemplateColumns: "minmax(230px, 455px) auto" },
|
|
31
|
+
"@supports not (container-type: inline-size)": { tabletWide: { gridTemplateColumns: "minmax(230px, 455px) auto" } }
|
|
32
|
+
},
|
|
33
|
+
right: {
|
|
34
|
+
"@/tablet": { gridTemplateColumns: "auto minmax(230px, 455px)" },
|
|
35
|
+
"@supports not (container-type: inline-size)": { tabletWide: { gridTemplateColumns: "auto minmax(230px, 455px)" } }
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
background: {
|
|
39
|
+
neutral: {},
|
|
40
|
+
brand1: { backgroundColor: "surface.brand.1" },
|
|
41
|
+
brand3: { backgroundColor: "surface.brand.3" }
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
defaultVariants: {
|
|
45
|
+
imageSide: "left",
|
|
46
|
+
background: "neutral"
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
const StyledImg = styled("img", { base: {
|
|
50
|
+
objectFit: "cover",
|
|
51
|
+
width: "100%",
|
|
52
|
+
height: "215px",
|
|
53
|
+
"@/tablet": { height: "340px" },
|
|
54
|
+
"@supports not (container-type: inline-size)": {
|
|
55
|
+
tablet: { height: "265px" },
|
|
56
|
+
tabletWide: { height: "340px" }
|
|
57
|
+
},
|
|
58
|
+
backgroundColor: "background.default"
|
|
59
|
+
} });
|
|
60
|
+
const ContentWrapper = styled("div", { base: {
|
|
61
|
+
width: "100%",
|
|
62
|
+
display: "flex",
|
|
63
|
+
flexDirection: "column",
|
|
64
|
+
gap: "medium",
|
|
65
|
+
alignItems: "flex-start",
|
|
66
|
+
justifyContent: "center",
|
|
67
|
+
paddingBlock: "medium",
|
|
68
|
+
paddingInline: "medium",
|
|
69
|
+
position: "relative"
|
|
70
|
+
} });
|
|
71
|
+
const StyledText = styled(Text, { base: { tablet: {
|
|
72
|
+
display: "block",
|
|
73
|
+
overflow: "hidden",
|
|
74
|
+
position: "relative",
|
|
75
|
+
lineClamp: 4,
|
|
76
|
+
boxOrient: "vertical"
|
|
77
|
+
} } });
|
|
78
|
+
const StyledSafeLinkButton = styled(SafeLinkButton, { base: {
|
|
79
|
+
boxShadow: "full",
|
|
80
|
+
border: "1px solid",
|
|
81
|
+
borderColor: "stroke.default"
|
|
82
|
+
} });
|
|
83
|
+
const LinkButton = ({ url, children, path }) => {
|
|
84
|
+
if (url) return /* @__PURE__ */ jsx(StyledSafeLinkButton, {
|
|
85
|
+
to: getPossiblyRelativeUrl(url, path),
|
|
86
|
+
variant: "secondary",
|
|
87
|
+
rel: "noopener noreferrer",
|
|
88
|
+
children
|
|
89
|
+
});
|
|
90
|
+
return children;
|
|
91
|
+
};
|
|
92
|
+
const CampaignBlock = ({ title, image, imageSide = "left", description, headingLevel: InternalHeading = "h2", url, path, className, background }) => {
|
|
93
|
+
const imageComponent = image && /* @__PURE__ */ jsx(StyledImg, {
|
|
94
|
+
src: `${image.src}?width=455`,
|
|
95
|
+
height: 340,
|
|
96
|
+
width: 455,
|
|
97
|
+
alt: image.alt
|
|
98
|
+
});
|
|
99
|
+
return /* @__PURE__ */ jsx(Wrapper, { children: /* @__PURE__ */ jsxs(Container, {
|
|
100
|
+
className,
|
|
101
|
+
"data-embed-type": "campaign-block",
|
|
102
|
+
imageSide,
|
|
103
|
+
background,
|
|
104
|
+
children: [
|
|
105
|
+
imageSide === "left" && imageComponent,
|
|
106
|
+
/* @__PURE__ */ jsxs(ContentWrapper, { children: [
|
|
107
|
+
/* @__PURE__ */ jsx(Text, {
|
|
108
|
+
asChild: true,
|
|
109
|
+
consumeCss: true,
|
|
110
|
+
textStyle: "heading.small",
|
|
111
|
+
children: /* @__PURE__ */ jsx(InternalHeading, { children: parse(title) })
|
|
112
|
+
}),
|
|
113
|
+
/* @__PURE__ */ jsx(StyledText, {
|
|
114
|
+
textStyle: "body.xlarge",
|
|
115
|
+
children: parse(description)
|
|
116
|
+
}),
|
|
117
|
+
!!url?.url && /* @__PURE__ */ jsxs(LinkButton, {
|
|
118
|
+
url: url.url,
|
|
119
|
+
path,
|
|
120
|
+
children: [parse(url.text ?? ""), /* @__PURE__ */ jsx(ArrowRightLine, {})]
|
|
121
|
+
})
|
|
122
|
+
] }),
|
|
123
|
+
imageSide !== "left" && imageComponent
|
|
124
|
+
]
|
|
125
|
+
}) });
|
|
126
|
+
};
|
|
127
|
+
var CampaignBlock_default = CampaignBlock;
|
|
128
|
+
|
|
129
|
+
//#endregion
|
|
130
|
+
export { CampaignBlock_default };
|
|
131
|
+
//# sourceMappingURL=CampaignBlock.js.map
|