Skip to content

Commit

Permalink
feat: add --langtag-top, --langtag-right style props (#327)
Browse files Browse the repository at this point in the history
Closes #324
  • Loading branch information
metonym committed Feb 6, 2024
1 parent 8c51fa2 commit 4aca589
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 11 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,8 @@ See the [Languages page](SUPPORTED_LANGUAGES.md) for a list of supported languag

| Style prop | Description | Default value |
| :---------------------- | :------------------------------ | :------------ |
| --langtag-top | Top position of the langtag | `0` |
| --langtag-right | Right position of the langtag | `0` |
| --langtag-background | Background color of the langtag | `inherit` |
| --langtag-color | Text color of the langtag | `inherit` |
| --langtag-border-radius | Border radius of the langtag | `0` |
Expand Down
14 changes: 14 additions & 0 deletions src/Highlight.svelte.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ export type LangtagProps = {
* displayed at the top right of the code block.
*
* Use style props to customize styles:
* - `--langtag-top`
* - `--langtag-right`
* - `--langtag-background`
* - `--langtag-color`
* - `--langtag-border-radius`
Expand All @@ -17,6 +19,18 @@ export type LangtagProps = {
*/
langtag?: boolean;

/**
* Customize the top position of the langtag.
* @default 0
*/
"--langtag-top"?: string | number;

/**
* Customize the right position of the langtag.
* @default 0
*/
"--langtag-right"?: string | number;

/**
* Customize the background color of the langtag.
* @default "inherit"
Expand Down
4 changes: 2 additions & 2 deletions src/LangTag.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
.langtag::after {
content: attr(data-language);
position: absolute;
top: 0;
right: 0;
top: var(--langtag-top, 0);
right: var(--langtag-right, 0);
display: flex;
align-items: center;
justify-content: center;
Expand Down
2 changes: 2 additions & 0 deletions tests/SvelteHighlightPackage.test.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,6 @@
--langtag-border-radius=""
--langtag-color=""
--langtag-padding=""
--langtag-top=""
--langtag-right=""
/>
21 changes: 12 additions & 9 deletions www/components/globals/Index.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -264,18 +264,17 @@
</Column>
<Column xlg={6} lg={12}>
<p class="mb-5">
All <code class="code">Highlight</code> components allow for a tag to be
added at the top-right of the codeblock displaying the language name.
Customize the language tag <code class="code">background</code>,
<code class="code">color</code>,
<code class="code">border-radius</code>, and
<code class="code">padding</code> using style props.
All <code class="code">Highlight</code> components allow for a tag to be added
at the top-right of the codeblock displaying the language name. Customize the
language tag using style props.
</p>
<p class="mb-5">Defaults:</p>
<UnorderedList class="mb-5">
<ListItem
><code class="code">--langtag-background: inherit</code></ListItem
>
<ListItem><code class="code">--langtag-top: 0</code></ListItem>
<ListItem><code class="code">--langtag-right: 0</code></ListItem>
<ListItem>
<code class="code">--langtag-background: inherit</code>
</ListItem>
<ListItem><code class="code">--langtag-color: inherit</code></ListItem>
<ListItem><code class="code">--langtag-border-radius: 0</code></ListItem>
<ListItem><code class="code">--langtag-padding: 1em</code></ListItem>
Expand All @@ -302,13 +301,17 @@
code={`<HighlightAuto
{code}
langtag
--langtag-top="0.5rem"
--langtag-right="0.5rem"
--langtag-background="linear-gradient(135deg, #2996cf, 80%, white)"
--langtag-color="#fff"
--langtag-border-radius="6px"
--langtag-padding="0.5rem"
/>`}
class="irBlack"
langtag
--langtag-top="0.5rem"
--langtag-right="0.5rem"
--langtag-background="linear-gradient(135deg, #2996cf, 80%, white)"
--langtag-color="#fff"
--langtag-border-radius="6px"
Expand Down

0 comments on commit 4aca589

Please sign in to comment.