Composables
Mark Element
Style highlighted text elements with configurable background, color, and padding using the useMarkElement composable.
Overview
The useMarkElement composable styles the mark element for highlighting text. It creates CSS variables for the background color, text color, and padding on each side.
useMarkElement
function useMarkElement(
s: Styleframe,
options?: WithThemes<MarkElementConfig>
): MarkElementResult
styleframe.config.ts
import { styleframe } from 'styleframe';
import { useMarkElement } from '@styleframe/theme';
const s = styleframe();
const {
markBackground,
markColor,
markPaddingTop,
markPaddingRight,
markPaddingBottom,
markPaddingLeft,
} = useMarkElement(s);
export default s;
styleframe/index.css
:root {
--mark--background: var(--color--warning-100);
--mark--color: inherit;
--mark--padding-top: 0.1875rem;
--mark--padding-right: 0.375rem;
--mark--padding-bottom: 0.1875rem;
--mark--padding-left: 0.375rem;
}
mark {
background: var(--mark--background);
color: var(--mark--color);
padding-top: var(--mark--padding-top);
padding-right: var(--mark--padding-right);
padding-bottom: var(--mark--padding-bottom);
padding-left: var(--mark--padding-left);
}
Default Values
| Option | Default | Variable | Export |
|---|---|---|---|
background | "@color.warning-100" | --mark--background | markBackground |
color | "inherit" | --mark--color | markColor |
paddingTop | "0.1875rem" | --mark--padding-top | markPaddingTop |
paddingRight | "0.375rem" | --mark--padding-right | markPaddingRight |
paddingBottom | "0.1875rem" | --mark--padding-bottom | markPaddingBottom |
paddingLeft | "0.375rem" | --mark--padding-left | markPaddingLeft |
The default configuration includes a dark theme that uses a darker background: background: "@color.warning-700".
Custom Values
styleframe.config.ts
import { styleframe } from 'styleframe';
import { useMarkElement } from '@styleframe/theme';
const s = styleframe();
const { markBackground } = useMarkElement(s, {
background: '@color.info-100',
paddingTop: '0.25rem',
paddingRight: '0.5rem',
paddingBottom: '0.25rem',
paddingLeft: '0.5rem',
});
export default s;
styleframe/index.css
:root {
--mark--background: var(--color--info-100);
--mark--color: inherit;
--mark--padding-top: 0.25rem;
--mark--padding-right: 0.5rem;
--mark--padding-bottom: 0.25rem;
--mark--padding-left: 0.5rem;
}
mark {
background: var(--mark--background);
color: var(--mark--color);
padding-top: var(--mark--padding-top);
padding-right: var(--mark--padding-right);
padding-bottom: var(--mark--padding-bottom);
padding-left: var(--mark--padding-left);
}
Best Practices
- Use warm highlight colors: The default
@color.warning-100provides a familiar yellow-highlight effect. Use@color.info-100for a cooler blue alternative. - Inherit the text color: The default
color: "inherit"keeps marked text readable against its background without overriding the parent color. - Customize per-theme: The built-in dark theme uses
@color.warning-700for a darker highlight. Override thethemesoption if your dark mode needs different values.