Skip to content

Commit 05554f1

Browse files
authored
feat: add --langtag-padding style prop (#325)
Closes #324
1 parent 96bc5db commit 05554f1

File tree

9 files changed

+62
-36
lines changed

9 files changed

+62
-36
lines changed

README.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,7 @@ See the [Languages page](SUPPORTED_LANGUAGES.md) for a list of supported languag
286286
| --langtag-background | Background color of the langtag | `inherit` |
287287
| --langtag-color | Text color of the langtag | `inherit` |
288288
| --langtag-border-radius | Border radius of the langtag | `0` |
289+
| --langtag-padding | Padding of the langtag | `1em` |
289290

290291
```svelte
291292
<script>
@@ -297,12 +298,15 @@ See the [Languages page](SUPPORTED_LANGUAGES.md) for a list of supported languag
297298
<HighlightAuto {code} langtag />
298299
```
299300

300-
```css
301-
[data-language="css"] {
302-
--langtag-background: linear-gradient(135deg, #2996cf, 80%, white);
303-
--langtag-color: #fff;
304-
--langtag-border-radius: 8px;
305-
}
301+
```svelte
302+
<HighlightAuto
303+
{code}
304+
langtag
305+
--langtag-background="linear-gradient(135deg, #2996cf, 80%, white)"
306+
--langtag-color="#fff"
307+
--langtag-border-radius="6px"
308+
--langtag-padding="0.5rem"
309+
/>
306310
```
307311

308312
## Custom Language

src/Highlight.svelte.d.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,27 @@ export type HighlightProps = HTMLAttributes<HTMLPreElement> & {
3131

3232
/**
3333
* Customize the background color of the langtag.
34+
* @default "inherit"
3435
*/
3536
"--langtag-background"?: string;
3637

3738
/**
3839
* Customize the text color of the langtag.
40+
* @default "inherit"
3941
*/
4042
"--langtag-color"?: string;
4143

4244
/**
4345
* Customize the border radius of the langtag.
46+
* @default 0
4447
*/
4548
"--langtag-border-radius"?: string;
49+
50+
/**
51+
* Customize the padding of the langtag.
52+
* @default "1em"
53+
*/
54+
"--langtag-padding"?: string;
4655
};
4756

4857
export type HighlightEvents = {

src/HighlightAuto.svelte.d.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,27 @@ export type HighlightAutoProps = HTMLAttributes<HTMLPreElement> & {
2222

2323
/**
2424
* Customize the background color of the langtag.
25+
* @default "inherit"
2526
*/
2627
"--langtag-background"?: string;
2728

2829
/**
2930
* Customize the text color of the langtag.
31+
* @default "inherit"
3032
*/
3133
"--langtag-color"?: string;
3234

3335
/**
3436
* Customize the border radius of the langtag.
37+
* @default 0
3538
*/
3639
"--langtag-border-radius"?: string;
40+
41+
/**
42+
* Customize the padding of the langtag.
43+
* @default "1em"
44+
*/
45+
"--langtag-padding"?: string;
3746
};
3847

3948
export type HighlightAutoEvents = {

src/HighlightSvelte.svelte.d.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,27 @@ export type HighlightSvelteProps = HTMLAttributes<HTMLPreElement> & {
2222

2323
/**
2424
* Customize the background color of the langtag.
25+
* @default "inherit"
2526
*/
2627
"--langtag-background"?: string;
2728

2829
/**
2930
* Customize the text color of the langtag.
31+
* @default "inherit"
3032
*/
3133
"--langtag-color"?: string;
3234

3335
/**
3436
* Customize the border radius of the langtag.
37+
* @default 0
3538
*/
3639
"--langtag-border-radius"?: string;
40+
41+
/**
42+
* Customize the padding of the langtag.
43+
* @default "1em"
44+
*/
45+
"--langtag-padding"?: string;
3746
};
3847

3948
export type HighlightSvelteEvents = {

src/LangTag.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@
2929
position: absolute;
3030
top: 0;
3131
right: 0;
32-
padding: 1em;
3332
display: flex;
3433
align-items: center;
3534
justify-content: center;
3635
background: var(--langtag-background, inherit);
3736
color: var(--langtag-color, inherit);
38-
border-radius: var(--langtag-border-radius);
37+
border-radius: var(--langtag-border-radius, 0);
38+
padding: var(--langtag-padding, 1em);
3939
}
4040
</style>

src/LangTag.svelte.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export type LangTagProps = HTMLAttributes<HTMLPreElement> & {
2626
* - `--langtag-background`
2727
* - `--langtag-color`
2828
* - `--langtag-border-radius`
29+
* - `--langtag-padding`
2930
*
3031
* @default false
3132
*/

tests/e2e/HighlightAuto.test.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@
99
{@html atomOneDark}
1010
</svelte:head>
1111

12-
<HighlightAuto {code} langtag={true} />
12+
<HighlightAuto {code} langtag />

www/app.css

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,6 @@
1010
line-height: 1.6;
1111
}
1212

13-
[data-language="css"] {
14-
--langtag-background: linear-gradient(135deg, #2996cf, 80%, white);
15-
--langtag-color: #fff;
16-
--langtag-border-radius: 8px;
17-
}
18-
19-
[data-language="svelte"] {
20-
--langtag-color: #fff;
21-
}
22-
2313
.code {
2414
position: relative;
2515
display: inline;

www/components/globals/Index.svelte

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -265,21 +265,19 @@
265265
<Column xlg={6} lg={12}>
266266
<p class="mb-5">
267267
All <code class="code">Highlight</code> components allow for a tag to be added
268-
at the top-right of the codeblock displaying the language name.
268+
at the top-right of the codeblock displaying the language name. Customize the language tag <code class="code">background</code>,
269+
<code class="code">color</code>,
270+
<code class="code">border-radius</code>, and
271+
<code class="code">padding</code> using style props.
269272
</p>
270-
<p class="mb-5">
271-
Customize the language tag <code class="code">background</code>,
272-
<code class="code">color</code>, and
273-
<code class="code">border-radius</code> using style props.
274-
</p>
275-
<p class="mb-5">This is also compatible with custom languages.</p>
276273
<p class="mb-5">Defaults:</p>
277274
<UnorderedList class="mb-5">
278275
<ListItem
279276
><code class="code">--langtag-background: inherit</code></ListItem
280277
>
281278
<ListItem><code class="code">--langtag-color: inherit</code></ListItem>
282279
<ListItem><code class="code">--langtag-border-radius: 0</code></ListItem>
280+
<ListItem><code class="code">--langtag-padding: 1em</code></ListItem>
283281
</UnorderedList>
284282
<p class="mb-5">
285283
See the <Link size="lg" href="/languages">Languages page</Link> for a list
@@ -294,20 +292,26 @@
294292
$: code = \`body {\n padding: 0;\n color: red;\n}\`;
295293
<\/script>
296294
297-
<HighlightAuto {code} langtag="{true}" \/>`}
295+
<HighlightAuto {code} langtag \/>`}
298296
class="irBlack"
299-
langtag={true}
297+
langtag
300298
/>
301299
<br />
302-
<Highlight
303-
code={`[data-language="css"] {
304-
--langtag-background: linear-gradient(135deg, #2996cf, 80%, white);
305-
--langtag-color: #fff;
306-
--langtag-border-radius: 8px;
307-
}`}
308-
language={css}
300+
<HighlightSvelte
301+
code={`<HighlightAuto
302+
{code}
303+
langtag
304+
--langtag-background="linear-gradient(135deg, #2996cf, 80%, white)"
305+
--langtag-color="#fff"
306+
--langtag-border-radius="6px"
307+
--langtag-padding="0.5rem"
308+
/>`}
309309
class="irBlack"
310-
langtag={true}
310+
langtag
311+
--langtag-background="linear-gradient(135deg, #2996cf, 80%, white)"
312+
--langtag-color="#fff"
313+
--langtag-border-radius="6px"
314+
--langtag-padding="0.5rem"
311315
/>
312316
</Column>
313317
</Row>

0 commit comments

Comments
 (0)