Skip to content

Commit 74e5c2c

Browse files
parloughTony Sansone
authored and
Tony Sansone
committed
Add custom styles for details-based dropdowns (dart-lang#5545)
Adds interaction styles and spacing to the details summary as well as spacing to the contents. An example of how this effects on a details usage on hover at `/language/isolates#complete-example`: <img width="984" alt="Hovering over the summary of a details dropdown" src="https://github.com/dart-lang/site-www/assets/18372958/8264ff11-cbea-4d51-8de2-f38b21b9a4e9"> Contributes to dart-lang#5382 which will use `<details>` as a replacement in some cases.
1 parent a9255ce commit 74e5c2c

File tree

3 files changed

+109
-93
lines changed

3 files changed

+109
-93
lines changed

src/_sass/core/_base.scss

+26
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,29 @@ blockquote {
8484
margin: 20px;
8585
padding: 10px 20px 0 20px;
8686
}
87+
88+
details {
89+
margin-bottom: 0.75rem;
90+
91+
> summary {
92+
font-weight: 500;
93+
user-select: none;
94+
95+
&:hover {
96+
color: $brand-primary;
97+
}
98+
}
99+
100+
&[open] {
101+
margin-bottom: unset;
102+
103+
> summary {
104+
margin-bottom: 0.75rem;
105+
}
106+
}
107+
108+
> :not(:first-child) {
109+
margin-left: 0.75rem;
110+
margin-right: 0.75rem;
111+
}
112+
}

src/content/codelabs/dart-cheatsheet.md

+40-51
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,7 @@ void main() {
6767
```
6868

6969
<details>
70-
<summary>
71-
<b>Solution for string interpolation example</b>
72-
</summary>
70+
<summary>Solution for string interpolation example</summary>
7371

7472
Both `x` and `y` are simple values,
7573
and Dart's string interpolation will handle
@@ -82,6 +80,7 @@ void main() {
8280
return '$x $y';
8381
}
8482
```
83+
8584
</details>
8685

8786

@@ -149,9 +148,7 @@ void main() {
149148
```
150149

151150
<details>
152-
<summary>
153-
<b>Solution for nullable variables example</b>
154-
</summary>
151+
<summary>Solution for nullable variables example</summary>
155152

156153
Declare the two variables as `String` followed by `?`.
157154
Then, assign `'Jane'` to `name`
@@ -161,6 +158,7 @@ void main() {
161158
String? name = 'Jane';
162159
String? address;
163160
```
161+
164162
</details>
165163

166164

@@ -233,9 +231,7 @@ void main() {
233231
```
234232

235233
<details>
236-
<summary>
237-
<b>Solution for null-aware operators example</b>
238-
</summary>
234+
<summary>Solution for null-aware operators example</summary>
239235

240236
All you need to do in this exercise is
241237
replace the `TODO` comments with either `??` or `??=`.
@@ -251,6 +247,7 @@ void main() {
251247
bar ??= 'a string';
252248
}
253249
```
250+
254251
</details>
255252

256253

@@ -324,9 +321,7 @@ void main() {
324321
```
325322

326323
<details>
327-
<summary>
328-
<b>Solution for conditional property access example</b>
329-
</summary>
324+
<summary>Solution for conditional property access example</summary>
330325

331326
If this exercise wanted you to conditionally lowercase a string,
332327
you could do it like this: `str?.toLowerCase()`. Use the equivalent
@@ -337,6 +332,7 @@ void main() {
337332
return str?.toUpperCase();
338333
}
339334
```
335+
340336
</details>
341337

342338
## Collection literals
@@ -455,9 +451,7 @@ void main() {
455451
```
456452

457453
<details>
458-
<summary>
459-
<b>Solution for collection literals example</b>
460-
</summary>
454+
<summary>Solution for collection literals example</summary>
461455

462456
Add a list, set, or map literal after each equals sign.
463457
Remember to specify the types for the empty declarations,
@@ -482,6 +476,7 @@ void main() {
482476
// Assign this an empty Map of double to int:
483477
final anEmptyMapOfDoublesToInts = <double, int>{};
484478
```
479+
485480
</details>
486481

487482
## Arrow syntax
@@ -576,9 +571,7 @@ void main() {
576571
```
577572

578573
<details>
579-
<summary>
580-
<b>Solution for arrow syntax example</b>
581-
</summary>
574+
<summary>Solution for arrow syntax example</summary>
582575

583576
For the product, you can use `*` to multiply the three values together.
584577
For `incrementValue1`, you can use the increment operator (`++`).
@@ -729,9 +722,7 @@ void main() {
729722
```
730723

731724
<details>
732-
<summary>
733-
<b>Solution for cascades example</b>
734-
</summary>
725+
<summary>Solution for cascades example</summary>
735726

736727
The best solution for this exercise starts with `obj..` and
737728
has four assignment operations chained together.
@@ -874,9 +865,8 @@ void main() {
874865
```
875866

876867
<details>
877-
<summary>
878-
<b>Solution for getters and setters example</b>
879-
</summary>
868+
<summary>Solution for getters and setters example</summary>
869+
880870
Two functions are handy for this exercise.
881871
One is `fold`, which can reduce a list to a single value
882872
(use it to calculate the total).
@@ -897,6 +887,7 @@ void main() {
897887
_prices = value;
898888
}
899889
```
890+
900891
</details>
901892

902893

@@ -1020,9 +1011,8 @@ void main() {
10201011
```
10211012

10221013
<details>
1023-
<summary>
1024-
<b>Solution for positional parameters example</b>
1025-
</summary>
1014+
<summary>Solution for positional parameters example</summary>
1015+
10261016
The `b`, `c`, `d`, and `e` parameters are null if they aren't provided by the
10271017
caller. The important thing, then, is to check whether those arguments are `null`
10281018
before you add them to the final string.
@@ -1037,6 +1027,7 @@ void main() {
10371027
return total;
10381028
}
10391029
```
1030+
10401031
</details>
10411032

10421033
<a id="optional-named-parameters"></a>
@@ -1165,9 +1156,8 @@ void main() {
11651156
```
11661157

11671158
<details>
1168-
<summary>
1169-
<b>Solution for named parameters example</b>
1170-
</summary>
1159+
<summary>Solution for named parameters example</summary>
1160+
11711161
The `copyWith` method shows up in a lot of classes and libraries.
11721162
Yours should do a few things:
11731163
use optional named parameters,
@@ -1387,9 +1377,8 @@ void main() {
13871377
```
13881378

13891379
<details>
1390-
<summary>
1391-
<b>Solution for exceptions example</b>
1392-
</summary>
1380+
<summary>Solution for exceptions example</summary>
1381+
13931382
This exercise looks tricky, but it's really one big `try` statement.
13941383
Call `untrustworthy` inside the `try`, and
13951384
then use `on`, `catch`, and `finally` to catch exceptions and
@@ -1408,6 +1397,7 @@ void main() {
14081397
}
14091398
}
14101399
```
1400+
14111401
</details>
14121402

14131403

@@ -1504,9 +1494,8 @@ void main() {
15041494
```
15051495

15061496
<details>
1507-
<summary>
1508-
<b>Solution for `this` example</b>
1509-
</summary>
1497+
<summary>Solution for `this` example</summary>
1498+
15101499
This exercise has a one-line solution.
15111500
Declare the constructor with
15121501
`this.anInt`, `this.aString`, and `this.aDouble`
@@ -1515,6 +1504,7 @@ void main() {
15151504
```dart
15161505
MyClass(this.anInt, this.aString, this.aDouble);
15171506
```
1507+
15181508
</details>
15191509

15201510
{% comment %}
@@ -1628,9 +1618,8 @@ void main() {
16281618
```
16291619

16301620
<details>
1631-
<summary>
1632-
<b>Solution for initializer lists example</b>
1633-
</summary>
1621+
<summary>Solution for initializer lists example</summary>
1622+
16341623
Two assignments need to happen:
16351624
`letterOne` should be assigned `word[0]`,
16361625
and `letterTwo` should be assigned `word[1]`.
@@ -1726,9 +1715,8 @@ void main() {
17261715
```
17271716

17281717
<details>
1729-
<summary>
1730-
<b>Solution for named constructors example</b>
1731-
</summary>
1718+
<summary>Solution for named constructors example</summary>
1719+
17321720
The declaration for your constructor should begin with `Color.black(): `.
17331721
In the initializer list (after the colon), set `red`, `green`, and `blue` to `0`.
17341722

@@ -1738,6 +1726,7 @@ void main() {
17381726
green = 0,
17391727
blue = 0;
17401728
```
1729+
17411730
</details>
17421731

17431732
## Factory constructors
@@ -1893,9 +1882,8 @@ void main() {
18931882
```
18941883

18951884
<details>
1896-
<summary>
1897-
<b>Solution for factory constructors example</b>
1898-
</summary>
1885+
<summary>Solution for factory constructors example</summary>
1886+
18991887
Inside the factory constructor,
19001888
check the length of the list, then create and return an
19011889
`IntegerSingle`, `IntegerDouble`, or `IntegerTriple` as appropriate.
@@ -1913,6 +1901,7 @@ void main() {
19131901
}
19141902
}
19151903
```
1904+
19161905
</details>
19171906

19181907
## Redirecting constructors
@@ -1993,14 +1982,14 @@ void main() {
19931982
```
19941983

19951984
<details>
1996-
<summary>
1997-
<b>Solution for redirecting constructors example</b>
1998-
</summary>
1985+
<summary>Solution for redirecting constructors example</summary>
1986+
19991987
Your constructor should redirect to `this(0, 0, 0)`.
20001988

20011989
```dart
20021990
Color.black() : this(0, 0, 0);
20031991
```
1992+
20041993
</details>
20051994

20061995
## Const constructors
@@ -2077,9 +2066,8 @@ void main() {
20772066
```
20782067

20792068
<details>
2080-
<summary>
2081-
<b>Solution for const constructors example</b>
2082-
</summary>
2069+
<summary>Solution for const constructors example</summary>
2070+
20832071
To make the constructor const, you'll need to make all the properties final.
20842072

20852073
```dart
@@ -2091,6 +2079,7 @@ void main() {
20912079
const Recipe(this.ingredients, this.calories, this.milligramsOfSodium);
20922080
}
20932081
```
2082+
20942083
</details>
20952084

20962085
## What's next?

0 commit comments

Comments
 (0)