Skip to content

Commit 40bae6b

Browse files
authored
Merge pull request #332 from appwrite/fix-alert-alignment
Fix: alignment when there's only title
2 parents 4e03f34 + 2158654 commit 40bae6b

3 files changed

Lines changed: 75 additions & 19 deletions

File tree

27.5 KB
Loading

v2/pink-sb/src/lib/alert/Inline.svelte

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -39,26 +39,37 @@
3939
class:error={status === 'error'}
4040
>
4141
<Stack gap="s" direction="row">
42-
<span class="primary-color">
43-
<Icon icon={getIcon()} />
42+
<span class="icon-holder" class:center-align={!$$slots.default}>
43+
<Icon icon={getIcon()} color="--alert-primary-color" />
4444
</span>
45+
4546
<Stack>
4647
<Stack gap="s" direction="row" justifyContent="space-between" alignItems="flex-start">
4748
<Stack>
48-
<div>
49-
{#if title}
50-
<h5 class="primary-color">{title}</h5>
51-
{/if}
52-
<slot />
53-
</div>
49+
{#if title || $$slots.default}
50+
<Stack gap="none">
51+
{#if title}
52+
<h5 style:color="var(--alert-primary-color)">{title}</h5>
53+
{/if}
54+
{#if $$slots.default}
55+
<slot />
56+
{/if}
57+
</Stack>
58+
{/if}
5459
{#if $$slots.actions}
5560
<Stack direction="row">
5661
<slot name="actions" />
5762
</Stack>
5863
{/if}
5964
</Stack>
65+
6066
{#if dismissible}
61-
<Button icon variant="text" size="s" on:click={() => dispatch('dismiss')}>
67+
<Button
68+
icon
69+
size="s"
70+
variant="extra-compact"
71+
on:click={() => dispatch('dismiss')}
72+
>
6273
<span class="close">
6374
<Icon icon={IconX} color="--fgcolor-neutral-tertiary" />
6475
</span>
@@ -79,6 +90,7 @@
7990
border-radius: var(--border-radius-s);
8091
border: var(--border-width-s) solid var(--border-neutral-strong);
8192
background: var(--bgcolor-neutral-default);
93+
--alert-primary-color: var(--fgcolor-info);
8294
8395
h5 {
8496
color: var(--fgcolor-neutral-primary);
@@ -90,26 +102,24 @@
90102
line-height: 140%; /* 19.6px */
91103
letter-spacing: -0.063px;
92104
}
105+
.icon-holder.center-align {
106+
display: flex;
107+
align-self: baseline;
108+
}
93109
&.success {
94110
border-color: var(--border-success-weak);
95111
background: var(--bgcolor-success-weaker);
96-
.primary-color {
97-
color: var(--fgcolor-success);
98-
}
112+
--alert-primary-color: var(--fgcolor-success);
99113
}
100114
&.warning {
101115
border-color: var(--border-warning-weak);
102116
background: var(--bgcolor-warning-weaker);
103-
.primary-color {
104-
color: var(--fgcolor-warning);
105-
}
117+
--alert-primary-color: var(--fgcolor-warning);
106118
}
107119
&.error {
108120
border-color: var(--border-error-weak);
109121
background: var(--bgcolor-error-weaker);
110-
.primary-color {
111-
color: var(--fgcolor-error);
112-
}
122+
--alert-primary-color: var(--fgcolor-error);
113123
}
114124
.close {
115125
color: var(--fgcolor-neutral-tertiary);

v2/pink-sb/src/stories/alert/Inline.stories.svelte

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,33 @@
1919
};
2020
</script>
2121

22-
<script>
22+
<script lang="ts">
23+
import { Layout, Typography } from '$lib/index.ts';
2324
import { Story, Template } from '@storybook/addon-svelte-csf';
25+
26+
const alerts = [
27+
{
28+
status: 'info',
29+
title: 'To complete, add this OAuth2 redirect URI to your Appwrite app config.',
30+
content: undefined
31+
},
32+
{
33+
status: 'success',
34+
title: 'OAuth2 redirect URI added successfully. Your Appwrite app is now ready!',
35+
content: 'You can now authenticate users via Appwrite without any additional setup.'
36+
},
37+
{
38+
status: 'warning',
39+
title: 'The OAuth2 redirect URI is missing. You may encounter login issues.',
40+
content:
41+
'To avoid authentication problems, ensure the URI is correctly added to your Appwrite app.'
42+
},
43+
{
44+
status: 'error',
45+
title: 'Failed to add OAuth2 redirect URI. Please try again or check your configuration.',
46+
content: undefined
47+
}
48+
] as const;
2449
</script>
2550

2651
<Template let:args>
@@ -36,3 +61,24 @@
3661
<Story name="Success" args={{ status: 'success' }} />
3762
<Story name="Warning" args={{ status: 'warning' }} />
3863
<Story name="Error" args={{ status: 'error' }} />
64+
<Story name="Only title">
65+
<div style:max-width="600px" style:margin-inline="auto" style:padding-block-start="4rem">
66+
<Layout.Stack gap="l">
67+
{#each alerts as alert}
68+
<Layout.Stack gap="xxxs">
69+
<Typography.Text variant="m-500">{alert.status.toUpperCase()}</Typography.Text>
70+
71+
{#if alert.content}
72+
<!-- with slot content -->
73+
<Alert.Inline title={alert.title} status={alert.status} dismissible>
74+
{alert.content}
75+
</Alert.Inline>
76+
{:else}
77+
<!-- without slot content -->
78+
<Alert.Inline title={alert.title} status={alert.status} dismissible />
79+
{/if}
80+
</Layout.Stack>
81+
{/each}
82+
</Layout.Stack>
83+
</div>
84+
</Story>

0 commit comments

Comments
 (0)