- Updated all component headers and documentation
- Changed navbar and footer branding
- Updated homepage hero badge
- Modified page title in index.html
- Simplified footer text to 'Built with ❤️'
- Consistent V2 capitalization across all references
65 lines
1.4 KiB
JavaScript
65 lines
1.4 KiB
JavaScript
function anatomy(name, map = {}) {
|
|
let called = false;
|
|
function assert() {
|
|
if (!called) {
|
|
called = true;
|
|
return;
|
|
}
|
|
throw new Error(
|
|
"[anatomy] .part(...) should only be called once. Did you mean to use .extend(...) ?"
|
|
);
|
|
}
|
|
function parts(...values) {
|
|
assert();
|
|
for (const part of values) {
|
|
map[part] = toPart(part);
|
|
}
|
|
return anatomy(name, map);
|
|
}
|
|
function extend(...parts2) {
|
|
for (const part of parts2) {
|
|
if (part in map)
|
|
continue;
|
|
map[part] = toPart(part);
|
|
}
|
|
return anatomy(name, map);
|
|
}
|
|
function selectors() {
|
|
const value = Object.fromEntries(
|
|
Object.entries(map).map(([key, part]) => [key, part.selector])
|
|
);
|
|
return value;
|
|
}
|
|
function classnames() {
|
|
const value = Object.fromEntries(
|
|
Object.entries(map).map(([key, part]) => [key, part.className])
|
|
);
|
|
return value;
|
|
}
|
|
function toPart(part) {
|
|
const el = ["container", "root"].includes(part ?? "") ? [name] : [name, part];
|
|
const attr = el.filter(Boolean).join("__");
|
|
const className = `chakra-${attr}`;
|
|
const partObj = {
|
|
className,
|
|
selector: `.${className}`,
|
|
toString: () => part
|
|
};
|
|
return partObj;
|
|
}
|
|
const __type = {};
|
|
return {
|
|
parts,
|
|
toPart,
|
|
extend,
|
|
selectors,
|
|
classnames,
|
|
get keys() {
|
|
return Object.keys(map);
|
|
},
|
|
__type
|
|
};
|
|
}
|
|
|
|
export { anatomy };
|