Skip to content

Commit b97da03

Browse files
authored
style(ToastContainer): toast container top positions starts after mas…[run-chromatic] (#517)
2 parents a366173 + c5682af commit b97da03

File tree

7 files changed

+101
-95
lines changed

7 files changed

+101
-95
lines changed

docs/INSTALLATION.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,10 @@ This method registers all SGDS elements up front in the Custom Elements Registry
6969
<link href='https://cdn.jsdelivr.net/npm/@govtechsg/sgds-web-component@3.6.4/css/sgds.css' rel='stylesheet' type='text/css' />
7070

7171
// it is recommended to load a particular version when using cdn e.g. https://cdn.jsdelivr.net/npm/@govtechsg/sgds-web-component@1.0.2
72-
<script src="https://cdn.jsdelivr.net/npm/@govtechsg/sgds-web-component@3.6.4" async crossorigin="anonymous" integrity="sha384-l2wDpDWqaG9T35wz73+vVSRD34GaxMBLrZXc0giBqUDltuRasNltLVL5XcqPZqH8"></script>
72+
<script src="https://cdn.jsdelivr.net/npm/@govtechsg/sgds-web-component@3.6.4" async crossorigin="anonymous" integrity="sha384-ztbQnGYW6IKQJzull/C3GPRHFK5yxTOSzW+PFPgsNHaHlQoadP0Rovsz4PnRVuO5"></script>
7373

7474
//or load a single component e.g. Masthead
75-
<script src="https://cdn.jsdelivr.net/npm/@govtechsg/sgds-web-component@3.6.4/components/Masthead/index.umd.min.js" async crossorigin="anonymous" integrity="sha384-kF8b8ASzezryQAXh/NhABOjzVo+K+zYbtKN77sVNT94MuN3tmg+Qz8g2n101gvWK"></script>
75+
<script src="https://cdn.jsdelivr.net/npm/@govtechsg/sgds-web-component@3.6.4/components/Masthead/index.umd.min.js" async crossorigin="anonymous" integrity="sha384-D6fmcLmJHlvW0xQlQo1kjqs2QlMWNEnEG6Lkv6cIG52HMoOpytomw7H6cMue1VSg"></script>
7676

7777
```
7878

playground/Toast.html

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,26 @@
33
<link href="../src/themes/night.css" rel="stylesheet" type="text/css" />
44
<link href="../src/css/sgds.css" rel="stylesheet" type="text/css" />
55

6+
<sgds-masthead></sgds-masthead>
7+
<sgds-system-banner show></sgds-system-banner>
8+
<sgds-mainnav></sgds-mainnav>
9+
<!-- <sgds-subnav>
10+
<h5 slot="header">STACKx Cybersecurity</h5>
11+
<sgds-subnav-item active><sgds-link size="sm"><a href="#">Overview</a></sgds-link></sgds-subnav-item>
12+
<sgds-subnav-item><sgds-link size="sm"><a href="#">On-site Activites</a></sgds-link></sgds-subnav-item>
13+
<sgds-subnav-item><sgds-link size="sm"><a href="#">Programme</a></sgds-link></sgds-subnav-item>
14+
<sgds-subnav-item><sgds-link size="sm"><a href="#">Speakers</a></sgds-link></sgds-subnav-item>
15+
<sgds-subnav-item><sgds-link size="sm"><a href="#">Partners</a></sgds-link></sgds-subnav-item>
16+
<sgds-subnav-item><sgds-link size="sm"><a href="#" target="_blank">Recordings</a></sgds-link></sgds-subnav-item>
17+
<sgds-subnav-item><sgds-link size="sm"><a href="#">FAQ</a></sgds-link></sgds-subnav-item>
18+
<sgds-button slot="actions" size="sm">Register now</sgds-button>
19+
<sgds-button slot="actions" size="sm">Exhibit</sgds-button>
20+
<sgds-button slot="actions" size="sm">Exhibit</sgds-button> -->
21+
<!-- </sgds-subnav> -->
22+
<sgds-toast-container>
623
<sgds-toast dismissible show>
724
<sgds-icon slot="icon" name="info-circle-fill"></sgds-icon>
825
This is a toast notifications This is a toast notifications his is a toast notifications his is a toast notifications
926
his is a toast notifications his is a toast notifications his is a toast notifications
1027
</sgds-toast>
28+
</sgds-toast-container>

src/components/Toast/sgds-toast-container.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,17 @@ import toastContainerStyle from "./toast-container.css";
1212
export class SgdsToastContainer extends SgdsElement {
1313
static styles = [toastContainerStyle];
1414

15-
/** Controls the position of `sgds-toast` within itself. When specified, toast container becomes position-absolute */
15+
/**
16+
* Controls the position of `sgds-toast` within itself.
17+
* Since 3.7.1, the positions "top-start", "middle-start", "middle-center", and "middle-end" are deprecated.
18+
*/
1619
@property({ type: String, reflect: true }) position: ToastPosition;
1720

1821
render() {
1922
return html`
2023
<div
2124
class=${classMap({
22-
"sgds toast-container": true,
25+
"toast-container": true,
2326
[this.position]: this.position
2427
})}
2528
>
Lines changed: 38 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,69 @@
1-
.toast-container {
2-
max-width: 100%;
3-
pointer-events: none;
4-
position: fixed;
5-
width: max-content;
6-
z-index: 1090;
7-
}
8-
1+
/* Deprecated since 3.7.1: top-start, middle-start, middle-center, middle-end */
92
.top-start {
10-
top: 0;
11-
left: 0;
12-
}
13-
14-
.top-center {
15-
top: 0;
16-
left: 50%;
17-
transform: translateX(-50%);
3+
top: var(--toast-container-top);
4+
left: var(--toast-container-left);
185
}
19-
20-
.top-end {
21-
top: 0;
22-
right: 0;
23-
}
24-
256
.middle-start {
267
top: 50%;
27-
left: 0;
8+
left: var(--toast-container-left);
289
transform: translateY(-50%);
2910
}
30-
3111
.middle-center {
3212
top: 50%;
3313
left: 50%;
3414
transform: translate(-50%, -50%);
3515
}
36-
3716
.middle-end {
3817
top: 50%;
39-
right: 0;
18+
right: var(--toast-container-right);
4019
transform: translateY(-50%);
4120
}
4221

22+
.toast-container {
23+
max-width: 100%;
24+
pointer-events: none;
25+
position: fixed;
26+
width: max-content;
27+
z-index: 1200;
28+
/* Height of masthead + mainnav */
29+
--toast-container-top: calc(28px + 80px + var(--sgds-spacer-8));
30+
--toast-container-right: var(--sgds-spacer-8);
31+
--toast-container-left: var(--sgds-spacer-8);
32+
--toast-container-bottom: var(--sgds-spacer-8);
33+
}
34+
35+
36+
.top-center {
37+
top: var(--toast-container-top);
38+
left: 50%;
39+
transform: translateX(-50%);
40+
}
41+
42+
.top-end {
43+
top: var(--toast-container-top);
44+
right: var(--toast-container-right);
45+
}
46+
4347
.bottom-start {
44-
bottom: 0;
45-
left: 0;
48+
bottom: var(--toast-container-bottom);
49+
left: var(--toast-container-left);
4650
}
4751

4852
.bottom-center {
49-
bottom: 0;
53+
bottom: var(--toast-container-bottom);
5054
left: 50%;
5155
transform: translateX(-50%);
5256
}
5357

5458
.bottom-end {
55-
bottom: 0;
56-
right: 0;
59+
bottom: var(--toast-container-bottom);
60+
right: var(--toast-container-right);
5761
}
5862

5963
slot {
6064
display: flex;
6165
flex-direction: column;
62-
gap: 0.5rem;
66+
gap: 0.5rem;
6367
}
68+
69+

stories/templates/Toast/additional.mdx

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,9 @@ Add `dismissible` prop to allow users to close the toast
4444
## Position with toast containers
4545

4646
ToastContainers positions the toast with respect to the entire page. Adjust the `position` prop accordingly to render your toast at the correct placements
47+
Top position takes into consideration the height of masthead and mainnav.
4748

4849

49-
### top-start
50-
51-
<Canvas of={ToastStories.TopStart}>
52-
<Story of={ToastStories.TopStart} />
53-
</Canvas>
54-
5550
### top-center
5651

5752
<Canvas of={ToastStories.TopCenter}>
@@ -64,24 +59,6 @@ ToastContainers positions the toast with respect to the entire page. Adjust the
6459
<Story of={ToastStories.TopEnd} />
6560
</Canvas>
6661

67-
### middle-start
68-
69-
<Canvas of={ToastStories.MiddleStart}>
70-
<Story of={ToastStories.MiddleStart} />
71-
</Canvas>
72-
73-
### middle-center
74-
75-
<Canvas of={ToastStories.MiddleCenter}>
76-
<Story of={ToastStories.MiddleCenter} />
77-
</Canvas>
78-
79-
### middle-end
80-
81-
<Canvas of={ToastStories.MiddleEnd}>
82-
<Story of={ToastStories.MiddleEnd} />
83-
</Canvas>
84-
8562
### bottom-start
8663

8764
<Canvas of={ToastStories.BottomStart}>

stories/templates/Toast/additional.stories.js

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -76,64 +76,65 @@ export const Dismissible = {
7676
tags: ["!dev"]
7777
};
7878

79-
export const TopStart = {
80-
render: Template.bind({}),
81-
name: "Top start",
82-
args: { ...args, position: "top-start" },
83-
parameters: {},
84-
tags: ["!dev"]
85-
};
79+
const PositionTemplate = args =>
80+
html`
81+
<div style="height:600px;">
82+
<sgds-masthead></sgds-masthead>
83+
<sgds-mainnav>
84+
<img
85+
alt="sgds logo"
86+
width="130"
87+
src="https://www.designsystem.tech.gov.sg/assets/img/logo-sgds.svg"
88+
slot="brand"
89+
/>
90+
</sgds-mainnav>
91+
<sgds-toast-container position=${ifDefined(args.position)}>
92+
<sgds-toast
93+
?show=${args.show}
94+
variant=${ifDefined(args.variant)}
95+
?autohide=${args.autohide}
96+
delay=${ifDefined(args.delay)}
97+
?noAnimation=${args.noAnimation}
98+
?dismissable=${args.dismissable}
99+
title=${ifDefined(args.title)}
100+
>
101+
<sgds-icon slot="icon" name="info-circle-fill"></sgds-icon>
102+
This is a toast notifications
103+
<sgds-link slot="action"><a href="#" target="_blank">Action</a></sgds-link>
104+
</sgds-toast>
105+
</sgds-toast-container>
106+
</div>
107+
`;
86108
export const TopCenter = {
87-
render: Template.bind({}),
109+
render: PositionTemplate.bind({}),
88110
name: "Top center",
89111
args: { ...args, position: "top-center" },
90112
parameters: {},
91113
tags: ["!dev"]
92114
};
93115
export const TopEnd = {
94-
render: Template.bind({}),
116+
render: PositionTemplate.bind({}),
95117
name: "Top end",
96118
args: { ...args, position: "top-end" },
97119
parameters: {},
98120
tags: ["!dev"]
99121
};
100-
export const MiddleStart = {
101-
render: Template.bind({}),
102-
name: "Middle start",
103-
args: { ...args, position: "middle-start" },
104-
parameters: {},
105-
tags: ["!dev"]
106-
};
107-
export const MiddleCenter = {
108-
render: Template.bind({}),
109-
name: "Middle center",
110-
args: { ...args, position: "middle-center" },
111-
parameters: {},
112-
tags: ["!dev"]
113-
};
114-
export const MiddleEnd = {
115-
render: Template.bind({}),
116-
name: "Middle end",
117-
args: { ...args, position: "middle-end" },
118-
parameters: {},
119-
tags: ["!dev"]
120-
};
121122
export const BottomStart = {
122-
render: Template.bind({}),
123+
render: PositionTemplate.bind({}),
123124
name: "Bottom start",
124125
args: { ...args, position: "bottom-start" },
125126
parameters: {},
126127
tags: ["!dev"]
127128
};
128129
export const BottomCenter = {
129-
render: Template.bind({}),
130+
render: PositionTemplate.bind({}),
130131
name: "Bottom Center",
131132
args: { ...args, position: "bottom-center" },
132133
parameters: {},
133134
tags: ["!dev"]
134135
};
135136
export const BottomEnd = {
136-
render: Template.bind({}),
137+
render: PositionTemplate.bind({}),
137138
name: "Bottom End",
138139
args: { ...args, position: "bottom-end" },
139140
parameters: {},
@@ -161,7 +162,7 @@ const StackingTemplate = () =>
161162
export const Stacking = {
162163
render: StackingTemplate.bind({}),
163164
name: "Stacking the toasts",
164-
args: {},
165+
args: { position: "bottom-end" },
165166
parameters: {},
166167
tags: ["!dev"]
167168
};

stories/templates/Toast/basic.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ export const Template = args =>
2323
`;
2424

2525
export const args = {
26-
show: true
26+
show: true,
27+
position: "bottom-end"
2728
};
2829

2930
export const parameters = {

0 commit comments

Comments
 (0)