Skip to content

Commit

Permalink
feat(css): add createId option
Browse files Browse the repository at this point in the history
  • Loading branch information
juanrgm committed Dec 26, 2022
1 parent f428fe7 commit 02740d8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/eleven-mugs-tap.md
@@ -0,0 +1,5 @@
---
"@suid/css": minor
---

Add `createId` option
14 changes: 10 additions & 4 deletions packages/css/src/createStyleObject.ts
Expand Up @@ -22,14 +22,14 @@ export type StyleObjectOptions = {
name: string;
props: StyleProps;
extraProperties?: Record<string, (value: any) => any>;
createId?: () => string;
cache?: StyleObjectCache;
};

function create(name: string, rules: string) {
const id = randomString().slice(0, 6);
function create(name: string, rules: string, id: string) {
return {
id,
name: name,
name,
className: `${name}-${id}`,
rules: rules.replaceAll(`$id`, `${id}`),
};
Expand All @@ -48,7 +48,13 @@ function createStyleObject(options: StyleObjectOptions) {
)
.join("\n");

const styleObject = options.cache?.get(rules) || create(options.name, rules);
const styleObject =
options.cache?.get(rules) ||
create(
options.name,
rules,
options.createId ? options.createId() : randomString().slice(0, 6)
);

if (options.cache) options.cache.set(rules, styleObject);

Expand Down

0 comments on commit 02740d8

Please sign in to comment.