Skip to content
This repository was archived by the owner on Sep 10, 2024. It is now read-only.

Commit 809893a

Browse files
committed
Compoundify the inputs
1 parent 7a9a873 commit 809893a

File tree

10 files changed

+99
-25
lines changed

10 files changed

+99
-25
lines changed

frontend/src/styles/cpd-form.css

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/* Copyright 2023 The Matrix.org Foundation C.I.C.
2+
*
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
/**
17+
* FIELD: Wrapper around label, control and message
18+
*/
19+
20+
.cpd-field {
21+
display: flex;
22+
flex-direction: column;
23+
}
24+
25+
/**
26+
* LABEL
27+
*/
28+
29+
.cpd-label {
30+
font-weight: var(--cpd-font-weight-medium);
31+
}
32+
33+
.cpd-label[for] {
34+
cursor: pointer;
35+
}
36+
37+
.cpd-label[data-invalid] {
38+
color: var(--cpd-color-text-critical-primary);
39+
}
40+
41+
/* Currently working everywhere but on Firefox (only behind a labs flag)
42+
https://developer.mozilla.org/en-US/docs/Web/CSS/:has#browser_compatibility */
43+
.cpd-label:has(~ .cpd-control[disabled]) {
44+
color: var(--cpd-color-text-disabled);
45+
cursor: not-allowed;
46+
}
47+
48+
/**
49+
* CONTROL
50+
*/
51+
52+
.cpd-control {
53+
border: 1px solid var(--cpd-color-border-interactive-primary);
54+
background: var(--cpd-color-bg-canvas-default);
55+
border-radius: 0.5rem;
56+
padding: var(--cpd-space-3x) var(--cpd-space-4x);
57+
box-sizing: border-box;
58+
}
59+
60+
.cpd-control:hover,
61+
input:hover ~ .cpd-control {
62+
border-color: var(--cpd-color-border-interactive-hovered);
63+
}
64+
65+
.cpd-control:focus,
66+
input:focus ~ .cpd-control {
67+
outline: 2px solid var(--cpd-color-border-focused);
68+
border-color: transparent;
69+
}
70+
71+
.cpd-control[data-invalid],
72+
input[data-invalid] ~ .cpd-control {
73+
border-color: var(--cpd-color-text-critical-primary);
74+
}
75+
76+
.cpd-control:disabled,
77+
input:disabled ~ .cpd-control {
78+
background: var(--cpd-color-bg-canvas-disabled);
79+
border-color: var(--cpd-color-border-disabled);
80+
color: var(--cpd-color-text-disabled);
81+
cursor: not-allowed;
82+
}

frontend/src/templates.css

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
@import "@vector-im/compound-design-tokens/assets/web/css/compound-design-tokens.css";
2121
@import "@vector-im/compound-web/dist/style.css";
2222
@import "./styles/cpd-button.css";
23+
@import "./styles/cpd-form.css";
2324
@import "./styles/cpd-link.css";
2425

2526
@config "../tailwind.templates.config.cjs";
@@ -35,4 +36,5 @@ body {
3536
font: var(--cpd-font-body-md-regular);
3637
background: var(--cpd-color-bg-canvas-default);
3738
color: var(--cpd-color-text-primary);
39+
letter-spacing: var(--cpd-font-letter-spacing-body-md);
3840
}

frontend/tailwind.config.cjs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ module.exports = {
2525
white: "#FFFFFF",
2626
secondary: "var(--cpd-color-text-secondary)",
2727
critical: "var(--cpd-color-text-critical-primary)",
28-
accent: "#0DBD8B",
2928
alert: "#FF5B55",
3029
links: "#0086E6",
3130
"grey-25": "#F4F6FA",
@@ -37,10 +36,6 @@ module.exports = {
3736
"grey-300": "#8E99A4",
3837
"grey-400": "#6F7882",
3938
"grey-450": "#394049",
40-
"black-800": "#15191E",
41-
"black-900": "#17191C",
42-
"black-950": "#21262C",
43-
ice: "#F4F9FD",
4439
},
4540
fontWeight: {
4641
semibold: "var(--cpd-font-weight-semibold)",

templates/components/field.html

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,12 @@
2121

2222
{% set state = form_state.fields[name] | default(value=dict(errors=[], value="")) %}
2323

24-
{% if state.errors is not empty %}
25-
{% set border_color = "border-alert" %}
26-
{% set text_color = "text-alert" %}
27-
{% else %}
28-
{% set border_color = "border-grey-50 dark:border-grey-450" %}
29-
{% set text_color = "text-black-800 dark:text-grey-300" %}
30-
{% endif %}
31-
32-
<label class="flex flex-col {{ class }}">
33-
<div class="mx-2 -mb-3 -mt-2 leading-5 px-1 z-10 self-start bg-white dark:bg-black-900 border-white border-2 dark:border-black-900 rounded-full text-sm {{ text_color }}">{{ label }}</div>
24+
<div class="flex flex-col cpd-field {{ class }}">
25+
<div class="cpd-label"{% if state.errors is not empty %} data-invalid{% endif %}>{{ label }}</div>
3426
<input name="{{ name }}"
35-
class="z-0 px-3 py-2 bg-white dark:bg-black-900 rounded-lg {{ border_color }} border-2 focus:border-accent focus:ring-0 focus:outline-0"
36-
type="{{ type }}"
27+
class="cpd-control"
28+
{% if state.errors is not empty %} data-invalid {% endif %}
29+
type="{{ type }}"
3730
inputmode="{{ inputmode }}"
3831
{% if required %} required {% endif %}
3932
{% if disabled %} disabled {% endif %}
@@ -45,7 +38,7 @@
4538
{% if state.errors is not empty %}
4639
{% for error in state.errors %}
4740
{% if error.kind != "unspecified" %}
48-
<div class="mx-4 text-sm text-alert">
41+
<div class="text-sm text-critical">
4942
{% if error.kind == "required" %}
5043
This field is required
5144
{% elif error.kind == "exists" and name == "username" %}
@@ -59,5 +52,5 @@
5952
{% endif %}
6053
{% endfor %}
6154
{% endif %}
62-
</label>
55+
</div>
6356
{% endmacro input %}

templates/pages/404.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121
<div class="w-64 flex flex-col gap-2">
2222
<h1 class="text-xl font-semibold">Page not found</h1>
2323
<p>The page you were looking for doesn't exist or has been moved</p>
24-
<a class="text-links hover:text-links/70" href="/">Go back to the homepage</a>
24+
<div>
25+
<a class="cpd-link" data-kind="primary" href="/">Go back to the homepage</a>
26+
</div>
2527

2628
<hr />
2729

templates/pages/account/emails/add.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ <h1 class="text-lg text-center font-medium">Add an email address</h1>
2626

2727
{% if form.errors is not empty %}
2828
{% for error in form.errors %}
29-
<div class="text-alert font-medium">
29+
<div class="text-critical font-medium">
3030
{{ errors::form_error_message(error=error) }}
3131
</div>
3232
{% endfor %}

templates/pages/account/emails/verify.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ <h1 class="text-lg text-center font-medium">Email verification</h1>
2727

2828
{% if form.errors is not empty %}
2929
{% for error in form.errors %}
30-
<div class="text-alert font-medium">
30+
<div class="text-critical font-medium">
3131
{{ errors::form_error_message(error=error) }}
3232
</div>
3333
{% endfor %}

templates/pages/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<h1 class="my-2 text-5xl font-semibold leading-tight">Matrix Authentication Service</h1>
2424
<p class="text-lg">
2525
OpenID Connect discovery document:
26-
<a class="text-links hover:text-links/70" href="{{ discovery_url }}">{{ discovery_url }}</a>
26+
<a class="cpd-link" data-kind="primary" href="{{ discovery_url }}">{{ discovery_url }}</a>
2727
</p>
2828
</div>
2929
</section>

templates/pages/login.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ <h1 class="text-lg text-center font-medium">Sign in</h1>
3434

3535
{% if form.errors is not empty %}
3636
{% for error in form.errors %}
37-
<div class="text-alert font-medium">
37+
<div class="text-critical font-medium">
3838
{{ errors::form_error_message(error=error) }}
3939
</div>
4040
{% endfor %}

templates/pages/register.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ <h1 class="text-lg text-center font-medium">Create an account</h1>
2525
</div>
2626
{% if form.errors is not empty %}
2727
{% for error in form.errors %}
28-
<div class="text-alert font-medium">
28+
<div class="text-critical font-medium">
2929
{{ errors::form_error_message(error=error) }}
3030
</div>
3131
{% endfor %}

0 commit comments

Comments
 (0)