Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fabric Web migration to Svelte #339

Merged
merged 25 commits into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
fb928e3
Start migrating fabric template
domlander Dec 18, 2023
1493c7b
Add AdvertisementLabel component and test.json
deedeeh Dec 27, 2023
dba7608
Add Pixel component and fabric index.svelte
deedeeh Dec 27, 2023
b69da95
Add export to index.ts to pass CI
deedeeh Dec 27, 2023
5aa41c7
Remove unnecessary files from this PR but adding the old func name
deedeeh Dec 28, 2023
2399969
Remove the unused key/value in test.json
deedeeh Dec 28, 2023
f088aa0
Addressed review comments
deedeeh Dec 29, 2023
bcfbccd
Refactored with css variables to reduce code
deedeeh Dec 29, 2023
d93467a
Add a 100% width preview
Jakeii Dec 29, 2023
86a06a5
Refactor gs-container in its own file
deedeeh Dec 29, 2023
7ffaf74
Add margin to gs-container and remove redundant code
deedeeh Dec 29, 2023
ee2b06e
Update src/templates/ssr/fabric/index.svelte
deedeeh Dec 29, 2023
6e04cef
Fix lint error
deedeeh Dec 29, 2023
bc27ba5
Replace media queries inside creative--fabric for specificity
deedeeh Jan 5, 2024
cd3cc48
Relocate fabric web to csr for parallax functionality
deedeeh Jan 11, 2024
25cd3c9
Add ad.json with the fabric-web native style id
deedeeh Jan 11, 2024
db57c7c
Add css rule background size cover for non parallax ads
deedeeh Jan 16, 2024
c7220c3
Start migrating fabric template
domlander Dec 18, 2023
60ce79e
Add AdvertisementLabel component and test.json
deedeeh Dec 27, 2023
571bbb0
Remove unnecessary files from this PR but adding the old func name
deedeeh Dec 28, 2023
f3da325
Update advertisement label not to use pallette (will be reinstated in…
domlander Jan 25, 2024
0b11f10
Use simpler class names. Remove helpers file.
domlander Jan 25, 2024
91486d0
delete superfluous files
domlander Jan 25, 2024
d7e616e
fix ad label positioning. Remove unneeded media queries
domlander Jan 25, 2024
833aff9
Correct width of ad and ad label
domlander Jan 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/lib/Previews.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
].join('');

export const widths = {
'100%': '100%',
1300: 'wide',
980: 'desktop',
740: 'tablet',
Expand Down Expand Up @@ -70,7 +71,7 @@

<section id="example">
{#each Object.keys(widths) as width}
<div class="size">
<div class="size {width === '100%' && 'full-width'}">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In Svelte, this is more semantically achieved by the class: directive

<div class="size" class:full-width={width === 100%}>

<h4>
{widths[width]} size ({width})
</h4>
Expand Down Expand Up @@ -107,7 +108,7 @@
</ul>
</section>

<style>
<style lang="scss">
#example {
box-sizing: border-box;
width: 100%;
Expand All @@ -121,6 +122,10 @@
display: flex;
flex-direction: column;
width: max-content;

&.full-width {
width: 100%;
}
}

iframe {
Expand Down
2 changes: 2 additions & 0 deletions src/lib/gam.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const CLICK_MACRO = '%%CLICK_URL_UNESC%%';
const CACHE_BUST = '%%CACHEBUSTER%%';
const DEST_URL = '%%DEST_URL%%';

type GAMVariable<T extends string = string> = T;

Expand Down Expand Up @@ -36,6 +37,7 @@ export type { GAMVariable };
export {
CACHE_BUST,
CLICK_MACRO,
DEST_URL,
addTrackingPixel,
gamVar,
isValidReplacedVariable,
Expand Down
40 changes: 23 additions & 17 deletions src/lib/messenger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ type ResizeMessage = StandardMessage<
{ width?: number | string; height?: number | string }
>;

type StringMessage = StandardMessage<'message', string>;

type BackgroundMessage = StandardMessage<
'background',
{
Expand All @@ -34,23 +32,36 @@ type BackgroundMessage = StandardMessage<
}
>;

type TypeMessage = StandardMessage<'type', string>;

type GetPageURLMessage = StandardMessage<'get-page-url', string>;
type FabricBackgroundMessage = StandardMessage<
'background',
{
scrollType: string;
backgroundColor: string;
backgroundImage: string;
backgroundRepeat: string;
backgroundPosition: string;
}
>;

type PassbackRefreshMessage = StandardMessage<'passback-refresh', string>;
type StringMessage = StandardMessage<
| 'message'
| 'type'
| 'get-page-url'
| 'passback-refresh'
| 'viewport'
| 'scroll',
string
>;

type Message =
| ResizeMessage
| StringMessage
| BackgroundMessage
| TypeMessage
| GetPageURLMessage
| PassbackRefreshMessage;
| FabricBackgroundMessage;

type MessengerResponse = {
id: string;
result: string;
result: unknown;
};

const generateId = () => {
Expand Down Expand Up @@ -79,12 +90,7 @@ const post = (arg: Message): void => {

const isReplyFromMessenger = (json: unknown): json is MessengerResponse => {
const reply = json as MessengerResponse;
return (
'result' in reply &&
typeof reply.result === 'string' &&
'id' in reply &&
typeof reply.id === 'string'
);
return 'result' in reply && 'id' in reply && typeof reply.id === 'string';
};

const decodeReply = (e: MessageEvent<string>): MessengerResponse | void => {
Expand All @@ -101,7 +107,7 @@ const decodeReply = (e: MessageEvent<string>): MessengerResponse | void => {
}
};

const postAndListen = (arg: Message): Promise<string | void> =>
const postAndListen = (arg: Message): Promise<unknown | void> =>
timeout(
new Promise((resolve) => {
const id = generateId();
Expand Down
53 changes: 53 additions & 0 deletions src/templates/components/AdvertisementLabel.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<script lang="ts">
deedeeh marked this conversation as resolved.
Show resolved Hide resolved
export let fullWidth: boolean;
</script>

<div class="container" class:fullWidth>
<div class="text">Advertisement</div>
</div>

<style lang="scss">
@import './fonts/Sans.css';

.container {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the label won't be aligned with the ad on larger screens without the helpers media queries

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right the label is not aligned. I tried it with the media queries but it didn't work. I had to add the padding to replicate the behaviour of the live site.

On a separate note, I notice the layers don't behave correctly with the media queries. I removed them and now I believe the behaviour is aligned to legacy

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without the media queries the ad won't be constrained to certain widths at certain breakpoints like the current fabric is?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a bit confusing because fixed ads behave differently to parallax ads. The background image of the parallax ads is controlled by the commercial code and is outside this template so doesn't respect these media queries.

I've reinstated the media queries, but for parallax ads I've allowed the ad label to go full-width and used padding to place it in the correct position on large screens

position: relative;
height: 2em;
background-color: #f6f6f6;
border-top: 1px solid #dcdcdc;
color: #707070;
font-family: 'GuardianTextSans', 'Helvetica Neue', Helvetica, Arial,
'Lucida Grande', sans-serif;
font-size: 0.75rem;
line-height: 1.9;
font-weight: 400;
box-sizing: border-box;

&.fullWidth {
padding: 0 calc(50% - 650px); // Keep the label central for large screens
}

&:not(.fullWidth) {
margin: 0 auto;
@media (min-width: 740px) {
max-width: 740px;
}
@media (min-width: 980px) {
max-width: 980px;
}
@media (min-width: 1140px) {
max-width: 1140px;
}
@media (min-width: 1300px) {
max-width: 1300px;
}
}
}

.text {
padding: 0 10px;

@media (min-width: 740px) {
padding: 0 20px;
}
}
</style>
16 changes: 16 additions & 0 deletions src/templates/components/Pixel.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<script lang="ts">
export let src: string;
</script>

<img {src} alt="" class="pixel" />

<style lang="scss">
.pixel {
position: absolute;
bottom: 0;
right: 0;
width: 1px;
height: 1px;
opacity: 0;
}
</style>
Comment on lines +7 to +16
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As Svelte scopes styles automaticall, you can apply the styles directly to img without the need for a specific class name.

128 changes: 128 additions & 0 deletions src/templates/components/colours/palette.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
$guardian-brand: #c70000;
Copy link
Contributor

@domlander domlander Jan 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've created a ticket in the backlog for us to use this palette, as we currently don't use it

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some of these colour values could use a Source makeover too 💅

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will add this as a note on the newly created ticket

$guardian-brand-light: #94b1ca;
$guardian-brand-dark: #121212;

$error: #d61d00;
$success: #4a7801;

// Neutral palette
$neutral-1: #333333;
$neutral-2: #767676;
$neutral-3: #bdbdbd;
$neutral-4: #dcdcdc;
$neutral-5: #dfdfdf;
$neutral-6: #eaeaea;
$neutral-7: #f1f1f1;
$neutral-8: #f6f6f6;
$neutral-2-contrasted: darken($neutral-2, 3%);

// News palette
$news-main-1: #005689;
$news-main-2: #4bc6df;
$news-support-1: #aad8f1;
$news-support-2: #197caa;
$news-support-3: #69d1ca;
$news-support-4: #66a998;
$news-support-5: #aad801;
$news-support-6: #63717a;
$news-support-7: #484f53;

// Features palette
$features-main-1: #7d0068;
$features-main-2: #b82266;
$features-support-1: #951c55;
$features-support-2: #4e0375;
$features-support-3: #fdadba;
$features-support-4: #dc2a7d;

// Comment palette
$comment-main-1: #c05303;
$comment-main-2: #ff9b0b;
$comment-support-1: #7d7569;
$comment-support-2: #efefec;
$comment-support-3: #ffce4b;
$comment-support-4: #e6711b;

// Multimedia palette
$multimedia-main-1: #333333;
$multimedia-main-2: #c70000;
$multimedia-support-1: #c5d4ea;
$multimedia-support-2: #507892;
$multimedia-support-3: #002c59;
$multimedia-support-4: #484848;
$multimedia-support-5: #161616;

// Futurelearn palette
$futurelearn-main-1: #333333;
$futurelearn-main-2: #f18b00;
$futurelearn-support-1: #c5d4ea;
$futurelearn-support-2: #507892;
$futurelearn-support-3: #002c59;
$futurelearn-support-4: #484848;
$futurelearn-support-5: #161616;

// Live palette
$live-main-1: #f5b3c7;
$live-main-2: #e71c77;
$live-support-1: #ff5b3a;
$live-support-2: #800c0c;
$live-support-3: #a60947;

// Maps palette
$maps-main-1: #1c6326;
$maps-main-2: #298422;
$maps-support-1: #ceb41d;
$maps-support-2: #a9af2b;
$maps-support-3: #5ebfba;
$maps-support-4: #72af7e;

// External content palette
$external-main-1: #1c6326;
$external-support-1: #a9af2b;

$paid-article: #d9d9d9;
$paid-article-bg: #d1d1d1;
$paid-article-header: #bfbfbf;
$paid-article-header-bg: #b8b8b8;
$paid-article-subheader: #f6f6f6;
$paid-article-subheader-bg: #c4c4c4;
$paid-article-media-bg: #bbb7b1;
$paid-article-icon: #767676;
$paid-article-brand: #69d1ca;
$paid-article-mpu: #cccccc;
$paidfor-background: $news-support-3;
$rainbow-red: #ed1c24; // from Guss
$paid-card-kicker: #626262;

$media-background: $multimedia-support-5;

// Membership
// =============================================================================

$membership-default: #2d4391;

// Lifestyle (magenta)
$lifestyle-dark: #7d0068;
$lifestyle-main: #bb3b80;
$lifestyle-bright: #ffabdb;
$lifestyle-pastel: #fec8d3;
$lifestyle-faded: #feeef7;

// New garnett colours
// =============================================================================

$guardian-books-rebrand: #8e246f;
$guardian-live-rebrand: #c83877;
$guardian-jobs-rebrand: #469d93;
$guardian-travel-rebrand: #007ba6;
$guardian-money-rebrand: #b39069;
$guardian-masterclasses-rebrand: #f4bc44;
$guardian-subscriptions-rebrand: #d01317;
$guardian-subscriptions-rebrand-blue: #005689;
$guardian-generic-rebrand: #012937;
$guardian-weekly-rebrand: #2c363b;
$guardian-members-rebrand: #bb3a7f;
$news-garnett-highlight: #ffe500;
$guardian-patron: #4f5249;
$guardian-highlight-hover: #f2ae00;
$guardian-support: #ff7f0f;
3 changes: 3 additions & 0 deletions src/templates/csr/fabric/ad.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"nativeStyleId": "71299"
}
Loading
Loading