aboutsummaryrefslogtreecommitdiff
path: root/examples/todo-list/style.css
blob: d4cd391d902c59471a48620db666320d5d775b00 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
:root {
  --color-gray: #cccccc;
  --color-accent: #5180e9;

  font-size: 16px;
  color: #555;

  --cssx-children: main#container;
}

body * { box-sizing: border-box; }

#container {
  max-width: 600px;
  margin: 2rem auto;
  border: 1px solid var(--color-gray);
  border-radius: 5px;
  overflow: hidden;

  --cssx-children: form#task-input-form #task-list;
}

#task-input-form {
  display: flex;
  width: 100%;

  /* prettier-ignore */
  --cssx-on-submit:
    prevent-default()
    add-children(
      task-list,
      instance(div#task-item, map(--text: attr(text-input, 'value')))
    )
    set-attr(text-input, value, '')
  ;

  /* prettier-ignore */
  --cssx-on-mount:
    add-children(
      task-list,
      instance(div#task-item, map(--text: "Buy lemons"))
    )
    add-children(
      task-list,
      instance(div#task-item, map(--text: "Make lemonaide"))
    )
    add-children(
      task-list,
      instance(div#task-item, map(--text: "Kill all the non-believers"))
    )
  ;

  /* prettier-ignore */
  --cssx-children:
    input#text-input[placeholder="Eg: Buy Milk"]
    button#create-task-btn[type=submit]
  ;
}

#text-input {
  display: block;
  width: 100%;
  padding: 0.7rem 1rem;
  font-size: 1rem;
  border: none;
  border-bottom: 1px solid var(--color-gray);
}

#create-task-btn {
  padding: 0 2rem;
  background-color: var(--color-accent);
  color: white;
  font-weight: bold;
  border: none;
  font-size: 1.2rem;

  --cssx-text: '+';
}

[data-instance=task-item] {
  --text: "default text";
  --done: "false";

  padding: 1rem;
  cursor: pointer;
  display: flex;
  width: 100%;
  align-items: center;

  --cssx-on-mount: update(--task-item-id, attr(data-element));

  --cssx-on-click: update(--done, if(get-var(--done), "false", "true"));
  --cssx-on-update: update(":scope [data-element=checkbox]", --checked, if(get-var(--done), true, false));

  --cssx-children: div#checkbox div#task-text button#delete-task;
}

[data-instance=task-item] [data-element=task-text] {
  flex: 2;
}
[data-instance=task-item] [data-element=task-text]::after {
  content: var(--text);
  padding-left: 0.8rem;
}

[data-instance=task-item]:not(:first-child) {
  content: "";
  border-top: 1px solid var(--color-gray);
}

[data-instance=task-item] [data-element=checkbox] {
  --checked: false;

  width: 18px;
  height: 18px;
  border: 2px solid gray;
  background-color: transparent;

  --cssx-on-update:
    update(background-color, if(get-var(--checked), get-var(--color-accent), transparent));
}

[data-instance=task-item] [data-element=delete-task] {
  --cssx-text: 'Delete';
  --cssx-on-click: remove-element(get-var(--task-item-id));
}