![Logo](/_astro/logo.DNC1PCTe_Z1abT04.webp)
Enter a search term above to see results...
Enter a search term above to see results...
The Browser utilities provide functions for common tasks in browser environments, such as copying text, handling keyboard events, and fetching text content.
function copyText(text)
Copies the provided text to the clipboard.
Name | Type | Description |
---|---|---|
text | string | The text to copy to the clipboard |
import { copyText } from '@semantic-ui/utils';
copyText('Hello, world!');console.log('Text copied to clipboard');
Browser Support This function uses the modern
navigator.clipboard.writeText
API. Ensure compatibility with your target browsers or provide a fallback for older browsers.
function getKeyFromEvent(event)
Extracts a standardized key representation from a keyboard event.
Name | Type | Description |
---|---|---|
event | KeyboardEvent | The keyboard event object |
A string representing the key pressed, including any modifier keys (e.g., “ctrl+a”).
import { getKeyFromEvent } from '@semantic-ui/utils';
document.addEventListener('keydown', (event) => { const key = getKeyFromEvent(event); console.log(`Key pressed: ${key}`);});
Modifier Keys This function handles modifier keys (Ctrl, Alt, Shift, Meta) and combines them with the pressed key. It also normalizes some key names for consistency.
async function getText(src)
Fetches text content from a given URL.
Name | Type | Description |
---|---|---|
src | string | The URL to fetch the text from |
A Promise that resolves with the fetched text content.
import { defineComponent } from '@semantic-ui/core';import { getText } from '@semantic-ui/utils';
const template = await getText('/templates/component.html');const css = await getText('/templates/component.css');
defineComponent({ template, css});
Usage Note This can be used on the server to load static assets like templates or css
function openLink(url, { newWindow = false, target, event } = {})
Opens a URL, optionally in a new window.
Name | Type | Description |
---|---|---|
url | string | The URL to open |
options | object | Optional configuration |
Name | Type | Default | Description |
---|---|---|---|
newWindow | boolean | false | Whether to open in a new window |
target | string | null | Target attribute for the link |
event | Event | null | Event object to prevent default behavior |
import { openLink } from '@semantic-ui/utils';
// Open in current windowopenLink('https://example.com');
// Open in new windowopenLink('https://example.com', { newWindow: true });
// Prevent default event behavioropenLink('https://example.com', { event: clickEvent });
async function getText(src)
Fetches text content from a URL.
Component Usage -
getText
can be used to retrieve html and css for use in a web component on the client from a separate file without a compilation step.
Name | Type | Description |
---|---|---|
src | string | The URL to fetch from |
A Promise that resolves with the text content.
import { getText } from '@semantic-ui/utils';
const content = await getText('https://example.com/content.txt');console.log(content);
async function getJSON(src)
Fetches and parses JSON content from a URL.
Name | Type | Description |
---|---|---|
src | string | The URL to fetch from |
A Promise that resolves with the parsed JSON content.
import { getJSON } from '@semantic-ui/utils';
const data = await getJSON('https://example.com/data.json');console.log(data);