Skip to content

Commit

Permalink
Stitching together
Browse files Browse the repository at this point in the history
  • Loading branch information
mikaelbr committed Nov 10, 2023
1 parent 03f8e72 commit 8a386d5
Show file tree
Hide file tree
Showing 5 changed files with 221 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"test": "vitest",
"dev": "next dev",
"build": "next build",
"build:widget": "yarn vite build ./src/widget",
"build:widget": "yarn vite build ./src/widget --emptyOutDir",
"build:all": "sh ./scripts/build.sh",
"build:docker": "sh ./scripts/build-docker.sh",
"start": "next start",
Expand Down
44 changes: 44 additions & 0 deletions src/pages/widget/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import DefaultLayout from '@atb/layouts/default';
import { withGlobalData, type WithGlobalData } from '@atb/layouts/global-data';
import type { NextPage } from 'next';
import Script from 'next/script';
import { useState } from 'react';

export type WidgetPageProps = WithGlobalData<{}>;

declare global {
interface Window {
PlannerWeb: {
output: string;
};
}
}
const AssistantPage: NextPage<WidgetPageProps> = (props) => {
const [isLoaded, setLoaded] = useState(false);
return (
<DefaultLayout {...props}>
<Script
src="/widget/planner-web.umd.js"
strategy="lazyOnload"
onLoad={() => {
setLoaded(true);

console.log(window.PlannerWeb);
}}
/>

<h1>Widget</h1>

{isLoaded && (
<>
<code>{window.PlannerWeb.output}</code>
<div dangerouslySetInnerHTML={{ __html: window.PlannerWeb.output }} />
</>
)}
</DefaultLayout>
);
};

export default AssistantPage;

export const getServerSideProps = withGlobalData();
18 changes: 18 additions & 0 deletions src/widget/vite.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
import { resolve } from 'path';
import { defineConfig } from 'vite';

const orgId = process.env.NEXT_PUBLIC_PLANNER_ORG_ID ?? 'atb';

export default defineConfig({
resolve: {
alias: {
'@atb/theme/theme.css': `@atb-as/theme/lib/themes/${orgId}-theme/theme.css`,
'@atb/theme/theme.module.css': `@atb-as/theme/lib/themes/${orgId}-theme/theme.module.css`,
'@atb/theme/typography.css': '@atb-as/theme/lib/typography.css',
'@atb/theme/typography.module.css':
'@atb-as/theme/lib/typography.module.css',
},
},
build: {
lib: {
// Could also be a dictionary or array of multiple entry points
Expand All @@ -17,4 +28,11 @@ export default defineConfig({
},
},
},
css: {
modules: {
scopeBehaviour: 'local',
// Make naming stable so we don't have to update HTML all the time.
generateScopedName: '[name]__[local]',
},
},
});
22 changes: 20 additions & 2 deletions src/widget/widget.module.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
.color {
color: red;
@value light from '@atb/theme/theme.module.css';

:root {
--ws-icon-size-xLarge: 2.5rem;

--ws-colors-header-border-bottom: #ffffff;
}

@media (max-width: 400px) {
:root {
--ws-icon-size-xLarge: 1.75rem;
}
}

.container {
composes: light;
}

.foo {
color: blue;
}
142 changes: 138 additions & 4 deletions src/widget/widget.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,141 @@
import style from './widget.module.css';

const html = `
<div class="${style.color}">Hello</div>
`;
const html = String.raw;

console.log(html);
export const output = html`
<div class="${style.container}">
<form class="${style.container}">
<div class="departures_main__T9IOc" style="padding-bottom: 5.75rem">
<div>
<p class="typo-body__primary--bold departures_heading__jfuQw">
Hvor vil du reise?
</p>
<div class="search_container__NfRBP">
<label
class="search_label__DgB_9 typography_typo-body__secondary__dROr2"
for="downshift-3-input"
id="downshift-3-label"
>Fra</label
>
<div
class="search_inputContainer__kN_LW"
role="combobox"
aria-expanded="false"
aria-haspopup="listbox"
aria-labelledby="downshift-3-label"
>
<input
class="search_input__NcSZd"
aria-autocomplete="list"
aria-labelledby="downshift-3-label"
autocomplete="off"
id="downshift-3-input"
value=""
/>
</div>
<button
class="departures_geolocationButton__TD_vW"
title="Finn min posisjon"
aria-label="Finn min posisjon"
type="button"
>
<img
src="/assets/mono/light/places/City.svg"
width="20"
height="20"
role="none"
alt=""
/>
</button>
<ul
class="search_menu__b2MHL"
role="listbox"
aria-labelledby="downshift-3-label"
id="downshift-3-menu"
></ul>
</div>
</div>
<div>
<p class="typo-body__primary--bold departures_heading__jfuQw">
Når vil du reise?
</p>
<div class="departure-date-selector_departureDateSelector__Fi7tg">
<div class="departure-date-selector_options__yYoHr">
<label class="departure-date-selector_option__LWD0K"
><input
type="radio"
name="departureDateSelector"
aria-label=""
class="departure-date-selector_option__input___RIte"
checked=""
value="now"
/><span
aria-hidden="true"
class="departure-date-selector_option__label__dkaL_"
><span
class="departure-date-selector_option__selected__AiilZ"
style="opacity: 1"
></span
><span class="departure-date-selector_option__text__2UuXR"
></span
></span
></label
><label class="departure-date-selector_option__LWD0K"
><input
type="radio"
name="departureDateSelector"
aria-label="Ankomst"
class="departure-date-selector_option__input___RIte"
value="arrival"
/><span
aria-hidden="true"
class="departure-date-selector_option__label__dkaL_"
><span class="departure-date-selector_option__text__2UuXR"
>Ankomst</span
></span
></label
><label class="departure-date-selector_option__LWD0K"
><input
type="radio"
name="departureDateSelector"
aria-label="Avgang"
class="departure-date-selector_option__input___RIte"
value="departure"
/><span
aria-hidden="true"
class="departure-date-selector_option__label__dkaL_"
><span class="departure-date-selector_option__text__2UuXR"
>Avgang</span
></span
></label
>
</div>
</div>
</div>
</div>
<div class="departures_buttons__vDSTI">
<button
type="button"
class="button_button__TIoc7 typography_typo-body__primary__kiR5z button_button--interactive_2__3dbxX button_button--size_small__ekxO4 button_button--radius_top-bottom__qd_4d button_button--radius_top-bottom__qd_4d departures_button__l2h50"
aria-disabled="false"
>
<span class="button_button__text__I8D_Z">Flere valg</span
><img
src="/assets/mono/light/actions/Adjust.svg"
width="20"
height="20"
role="none"
alt=""
/></button
><button
type="submit"
class="button_button__TIoc7 typography_typo-body__primary__kiR5z button_button--interactive_0__WdcFs button_button--disabled__2zVrc button_button--size_small__ekxO4 button_button--radius_top-bottom__qd_4d button_button--radius_top-bottom__qd_4d departures_button__l2h50"
disabled=""
aria-disabled="true"
>
<span class="button_button__text__I8D_Z">Finn avganger</span>
</button>
</div>
</form>
</div>
`;

0 comments on commit 8a386d5

Please sign in to comment.