Security News
Cloudflare Adds Security.txt Setup Wizard
Cloudflare has launched a setup wizard allowing users to easily create and manage a security.txt file for vulnerability disclosure on their websites.
The ak-theme
component allows you to define theme variables for components that can affect how they look and feel.
Interact with a live demo of the ak-theme component.
npm install ak-theme
The ak-theme
package exports the Theme Skate component.
Import the component in your JS resource:
import 'ak-theme';
Now you can use the defined tag in your HTML markup:
<html>
<head>
<script src="bundle.js"></script>
</head>
<body>
<!-- ... -->
<ak-theme></ak-theme>
</body>
or from within another JavaScript resource:
import Theme from 'ak-theme';
const component = new Theme();
document.body.appendChild(component);
This is a standard web component, if you want to use it in your React app, use the Skate.js React integration.
import Theme from 'ak-theme';
import reactify from 'skatejs-react-integration';
const ReactComponent = reactify(Theme, {});
ReactDOM.render(<ReactComponent />, container);
Theming is a two-part process:
Declaring a theme.
Make a component themeable.
If you want to theme a component, declare a theme and specify some variables:
<ak-theme id="my-component">
<ak-theme-var name="background" value="blue" />
<ak-theme-var name="text" value="white" />
</ak-theme>
This example declares a theme for a component called my-component
and exposes two variables:
background
text
To make a component able to be themed, use the themeable()
function that is exported from ak-theme
.
import { define } from 'skatejs';
import { themeable } from 'ak-theme';
export default define('my-component', themeable({
render(elem) {
return (
<style>
background-color: {elem.themeVars.background}
</style>
);
}
}));
The function themeable()
does several things for you:
themeVars
are always populated with the corresponding theme's variables.themeVars
is updated if the theme is updated.themeVars
is updated if the component's theme is changed.When using themeable()
you only have to worry about rendering your component based on some theme variables.
A themeable component's theme is a theme that has an id
that matches its tag name. However, if you need to change the theme a component should have, you can set its themeName
property. This property is also reflected, so you can use the theme-name
attribute just the same.
This is handy when the display of a particular component may changes depending on the parent's context.
<ak-button>My button</ak-button>
<ak-navigation>
<ak-button theme-name="nav-button">Navigation button</ak-button>
</ak-navigatoin>
string
The id of the theme the component should use. This defaults to the tag name of the component.
string
The deserialised variables from the component's current theme. These are automatically kept in sync.
string
The id of the theme the component should use. This defaults to the tag name of the component.
string
The deserialised variables from the component's current theme. These are automatically kept in sync.
Kind: global variable
Let us know what you think of our components and docs, your feedback is really important for us.
Ask a question in our forum.
Check if someone has already asked the same question before.
Are you in trouble? Let us know!
FAQs
ak-theme webcomponent
We found that ak-theme demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Cloudflare has launched a setup wizard allowing users to easily create and manage a security.txt file for vulnerability disclosure on their websites.
Security News
The Socket Research team breaks down a malicious npm package targeting the legitimate DOMPurify library. It uses obfuscated code to hide that it is exfiltrating browser and crypto wallet data.
Security News
ENISA’s 2024 report highlights the EU’s top cybersecurity threats, including rising DDoS attacks, ransomware, supply chain vulnerabilities, and weaponized AI.