hypnagaga/packages/graphics-components/docs/assets/cssVariables-BMSgMRIf.js

32 lines
1.6 KiB
JavaScript

import{j as e}from"./index-bIIEL2MP.js";import{useMDXComponents as r}from"./index-CO-0pc0F.js";import{M as o}from"./index-Z-6k0Xrj.js";import{p as a}from"./docsPage-CT2vyZOj.js";import"./_commonjsHelpers-D6-XlEtG.js";import"./iframe-CzjIX-qr.js";import"./index-aQYXhgXp.js";import"./index-DrFu-skq.js";function s(t){const n={a:"a",code:"code",h1:"h1",p:"p",pre:"pre",...r(),...t.components};return e.jsxs(e.Fragment,{children:[e.jsx(o,{title:"Actions/cssVariables",parameters:{...a}}),`
`,e.jsx(n.h1,{id:"cssvariables",children:e.jsx(n.code,{children:"cssVariables"})}),`
`,e.jsxs(n.p,{children:["An action you can use to easily set ",e.jsx(n.a,{href:"https://developer.mozilla.org/en-US/docs/Web/CSS/Using_CSS_custom_properties",rel:"nofollow",children:"CSS variables"})," on HTML elements. Useful for passing JavaScript values to your component SCSS like this:"]}),`
`,e.jsx(n.pre,{children:e.jsx(n.code,{className:"language-svelte",children:`<script>
import { cssVariables } from '@reuters-graphics/graphics-components';
let { height = 300, textColour = 'red' } = $props();
// Create an object of variable names and CSS values...
let variables = $derived({
height: height + 'px',
textColour: textColour,
});
<\/script>
<!-- Attach it to a parent element with the action -->
<div use:cssVariables={variables}>
<p>My text...</p>
</div>
<style lang="scss">
/**
* Now use your variables in your SCSS!
*/
div {
height: var(--height);
p {
color: var(--textColour);
}
}
</style>
`})})]})}function x(t={}){const{wrapper:n}={...r(),...t.components};return n?e.jsx(n,{...t,children:e.jsx(s,{...t})}):s(t)}export{x as default};