-
Notifications
You must be signed in to change notification settings - Fork 171
/
_patterns_code-snippet.scss
169 lines (138 loc) · 4.7 KB
/
_patterns_code-snippet.scss
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
/*
@classreference
code-snippet:
Root element:
.p-code-snippet:
Main element of the code snippet component.
"&.is-bordered":
Bordered variant, to be used when additional content (such as iframes) is used inside the code snippet component.
Code block:
.p-code-snippet__block:
Code block without any additional styling elements.
"&.is-wrapped":
Code block with wrapped content in lines.
.p-code-snippet__block--icon:
Code block that starts with an icon. Default icon is a UNIX prompt. To be used with Linux CLI examples.
"&.is-windows-prompt":
Changes the `.p-code-snippet__block--icon` to use a Windows prompt icon. To be used with Windows CLI examples.
"&.is-url":
Changes the `.p-code-snippet__block--icon` to use a link icon. To be used with URLs.
.p-code-snippet__block--numbered:
Code block with numbered lines of code (to be used with longer pieces of code examples). Requires `.p-code-snippet__line`.
Code line:
.p-code-snippet__line:
A wrapper around single line of code. Needed with numbered variant of a code block.
Code block header:
.p-code-snippet__header:
A header of a code block. Contains a title and optional dropdowns.
"&.is-stacked":
A stacked version of a header (with a title displayed above the dropdowns). To be used when there are multiple dropdowns with a long title.
Code block title:
.p-code-snippet__title:
The title of a code block.
Dropdowns container:
.p-code-snippet__dropdowns:
The container element for any dropdowns in the header.
Dropdown:
.p-code-snippet__dropdown:
An individual dropdown in code block header.
*/
@import 'settings';
$code-snippet-header-v-spacing: $spv--small;
@mixin vf-p-code-snippet {
.p-code-snippet {
margin-bottom: $spv--x-large;
&.is-bordered {
border: 1px solid $colors--theme--border-low-contrast;
}
.p-code-snippet__block,
.p-code-snippet__block--icon,
.p-code-snippet__block--numbered {
margin: 0;
&.is-wrapped {
white-space: pre-wrap;
}
}
.p-code-snippet__block--icon {
@extend %leading-linux-prompt-icon;
padding-left: #{$sph--large + map-get($icon-sizes, default) + $sph--small};
position: relative;
&.is-windows-prompt::before {
@include vf-icon-chevron-themed;
transform: rotate(270deg);
}
&.is-url::before {
@include vf-icon-get-link-themed;
}
}
.p-code-snippet__block--numbered {
counter-reset: line-numbering;
.p-code-snippet__line {
@extend %code-numbered-line;
}
}
.p-code-snippet__header {
align-items: flex-start;
background-color: $colors--theme--background-active;
display: flex;
justify-content: space-between;
padding-left: $sph--large;
padding-right: $sph--large;
}
.p-code-snippet__title {
@extend %vf-heading-5;
flex: 0 1 auto;
margin-bottom: $code-snippet-header-v-spacing;
overflow: hidden;
padding-top: $code-snippet-header-v-spacing;
text-overflow: ellipsis;
white-space: nowrap;
}
.p-code-snippet__dropdown {
background-color: $color-transparent;
border: 0;
color: $colors--theme--text-default;
margin-bottom: 0;
margin-left: $sph--small;
min-width: min-content;
padding-bottom: $code-snippet-header-v-spacing;
padding-left: $sph--large;
padding-top: $code-snippet-header-v-spacing;
width: min-content;
}
.p-code-snippet__dropdowns {
display: flex;
flex-shrink: 0;
&:first-child {
// if no header is present, use this to
// align the dropdowns to the right
margin-left: auto;
}
}
.p-code-snippet__dropdown + .p-code-snippet__dropdown {
border-left: 1px solid $colors--theme--border-default;
}
.p-code-snippet__header.is-stacked {
flex-direction: column;
.p-code-snippet__title {
white-space: normal;
}
.p-code-snippet__dropdowns {
flex: 1 0 100%;
justify-content: flex-end;
width: 100%;
}
.p-code-snippet__title + .p-code-snippet__dropdowns {
border-top: 1px solid $colors--theme--border-default;
}
}
// stylelint-disable-next-line selector-max-type
iframe {
margin: 0;
// fixes a Chrome bug where, on larger screens,
// a .is-bordered snippet's right border would
// disappear at every other pixel width increment
width: calc(100% - 1px);
}
}
}