Skip to content

Commit

Permalink
UU-disclaimer to new design
Browse files Browse the repository at this point in the history
  • Loading branch information
katrinewi committed Dec 13, 2024
1 parent d4ecacf commit 28c4c3d
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 78 deletions.
30 changes: 7 additions & 23 deletions packages/ndla-ui/src/Embed/UuDisclaimerEmbed.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,23 +47,7 @@ export const Regular: StoryObj<typeof UuDisclaimerEmbed> = {
resource: "uu-disclaimer",
status: "success",
embedData: embedData,
data: {},
},
},
};

export const WithLink: StoryObj<typeof UuDisclaimerEmbed> = {
args: {
embed: {
resource: "uu-disclaimer",
status: "success",
embedData: embedData,
data: {
disclaimerLink: {
href: "https://ndla.no/article/123",
text: "Navn på artikkel med innhold",
},
},
data: null,
},
},
};
Expand All @@ -74,7 +58,7 @@ export const WithIframe: StoryObj<typeof UuDisclaimerEmbed> = {
resource: "uu-disclaimer",
status: "success",
embedData: embedData,
data: {},
data: null,
},
children: (
<IframeEmbed
Expand All @@ -99,7 +83,7 @@ export const WithH5p: StoryObj<typeof UuDisclaimerEmbed> = {
resource: "uu-disclaimer",
status: "success",
embedData: embedData,
data: {},
data: null,
},
children: (
<H5pEmbed
Expand Down Expand Up @@ -135,7 +119,7 @@ export const WithHtml: StoryObj<typeof UuDisclaimerEmbed> = {
resource: "uu-disclaimer",
status: "success",
embedData: embedData,
data: {},
data: null,
},
children: (
<>
Expand All @@ -155,7 +139,7 @@ export const WithFramedContent: StoryObj<typeof UuDisclaimerEmbed> = {
resource: "uu-disclaimer",
status: "success",
embedData: embedData,
data: {},
data: null,
},
children: (
<FramedContent>
Expand All @@ -171,7 +155,7 @@ export const WithFactBox: StoryObj<typeof UuDisclaimerEmbed> = {
resource: "uu-disclaimer",
status: "success",
embedData: embedData,
data: {},
data: null,
},
children: (
<FactBox>
Expand All @@ -187,7 +171,7 @@ export const WithCopyParagraphLink: StoryObj<typeof UuDisclaimerEmbed> = {
resource: "uu-disclaimer",
status: "success",
embedData: embedData,
data: {},
data: null,
},
children: (
<CopyParagraphButton copyText="Dette er en overskrift" lang="no">
Expand Down
62 changes: 24 additions & 38 deletions packages/ndla-ui/src/Embed/UuDisclaimerEmbed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
*/

import { type ReactNode } from "react";
import { InformationLine } from "@ndla/icons";
import { MessageBox } from "@ndla/primitives";
import { SafeLink } from "@ndla/safelink";
import { Portal } from "@ark-ui/react";
import { AccesibilityLine } from "@ndla/icons";
import { Text, IconButton, PopoverContent, PopoverRoot, PopoverTrigger } from "@ndla/primitives";
import { styled } from "@ndla/styled-system/jsx";
import type { UuDisclaimerMetaData } from "@ndla/types-embed";

Expand All @@ -18,30 +18,17 @@ interface Props {
children?: ReactNode;
}

const StyledMessageBox = styled(MessageBox, {
const DisclaimerWrapper = styled("div", {
base: {
display: "flex",
alignItems: "center",
marginBlockEnd: "xsmall",
flexDirection: "column",
},
});
const Disclaimer = styled("div", {
base: {
textStyle: "body.medium",
},
});
const StyledSafeLink = styled(SafeLink, {

const StyledIconButton = styled(IconButton, {
base: {
paddingInlineStart: "4xsmall",
color: "text.link",
textDecoration: "underline",
whiteSpace: "nowrap",
_hover: {
textDecoration: "none",
},
_focusWithin: {
textDecoration: "none",
},
marginInlineStart: "auto",
marginBlockEnd: "3xsmall",
},
});

Expand All @@ -50,25 +37,24 @@ const UuDisclaimerEmbed = ({ embed, children }: Props) => {
return null;
}

const { embedData, data } = embed;

const disclaimerLink = data?.disclaimerLink ? (
<StyledSafeLink to={data.disclaimerLink.href} target="_blank" rel="noopener noreferrer">
{data.disclaimerLink.text}
</StyledSafeLink>
) : null;
const { embedData } = embed;

return (
<div role="region" data-embed-type="uu-disclaimer">
<StyledMessageBox variant="warning" contentEditable={false}>
<InformationLine />
<Disclaimer>
{embedData.disclaimer}
{disclaimerLink}
</Disclaimer>
</StyledMessageBox>
<DisclaimerWrapper role="region" data-embed-type="uu-disclaimer">
<PopoverRoot>
<PopoverTrigger asChild>
<StyledIconButton size="small" variant="secondary">
<AccesibilityLine />
</StyledIconButton>
</PopoverTrigger>
<Portal>
<PopoverContent>
<Text>{embedData.disclaimer}</Text>
</PopoverContent>
</Portal>
</PopoverRoot>
<div data-uu-content="">{children}</div>
</div>
</DisclaimerWrapper>
);
};

Expand Down
8 changes: 1 addition & 7 deletions packages/types-embed/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,7 @@ import type { KeyFigureEmbedData, KeyFigureMeta, KeyFigureMetaData } from "./key
import type { LinkBlockEmbedData, LinkBlockMetaData } from "./linkBlockTypes";
import type { PitchEmbedData, PitchMetaData, PitchMeta } from "./pitchTypes";
import type { RelatedContentData, RelatedContentEmbedData, RelatedContentMetaData } from "./relatedContentTypes";
import type {
DisclaimerLink,
UuDisclaimerData,
UuDisclaimerEmbedData,
UuDisclaimerMetaData,
} from "./uuDisclaimerTypes";
import type { UuDisclaimerEmbedData, UuDisclaimerMetaData } from "./uuDisclaimerTypes";

export type EmbedData =
| AudioEmbedData
Expand Down Expand Up @@ -155,7 +150,6 @@ export type { AudioMeta };
export type { H5pData };
export type { CampaignBlockMeta };
export type { OembedProxyData, H5pPreviewResponse, H5pOembedData, H5pLicenseInformation, H5pInfo };
export type { UuDisclaimerData, DisclaimerLink };

interface MetaDataFailure<T extends EmbedData> {
resource: T["resource"];
Expand Down
11 changes: 1 addition & 10 deletions packages/types-embed/src/uuDisclaimerTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,10 @@

import type { MetaData } from ".";

export interface DisclaimerLink {
text: string;
href: string;
}

export interface UuDisclaimerEmbedData {
resource: "uu-disclaimer";
disclaimer: string;
articleId?: string;
}

export interface UuDisclaimerData {
disclaimerLink?: DisclaimerLink;
}

export type UuDisclaimerMetaData = MetaData<UuDisclaimerEmbedData, UuDisclaimerData>;
export type UuDisclaimerMetaData = MetaData<UuDisclaimerEmbedData, null>;

0 comments on commit 28c4c3d

Please sign in to comment.