primevue-mirror/apps/showcase/components/doc/helpers/index.js

77 lines
2.6 KiB
JavaScript
Raw Normal View History

import APIDocs from '@/doc/common/apidoc/index.json';
2025-02-13 10:22:43 +00:00
import ComponentTokens from '@primeuix/themes/tokens';
2024-05-13 21:48:50 +00:00
export const getPTOptions = (name) => {
2023-08-07 13:14:43 +00:00
const { props } = APIDocs[name.toLowerCase()].interfaces.values[`${name}PassThroughOptions`] || APIDocs[name.toLowerCase()].interfaces.values[`${name}DirectivePassThroughOptions`];
const options = APIDocs[name.toLowerCase()].interfaces.values[`${name}PassThroughMethodOptions`];
let data = [];
for (const [i, prop] of props.entries()) {
if (options) {
let subCompName, subOptions;
let hasSubComp = prop.name !== 'hooks' && prop.type.indexOf('TransitionType') === -1 && prop.type.indexOf('<') > -1 && name.toLowerCase() !== prop.type.slice(0, prop.type.indexOf('<')).toLowerCase();
if (hasSubComp) {
subCompName = prop.type.slice(0, prop.type.indexOf('<')).replace('PassThroughOptions', '').replace('PassThroughOptionType', '');
subOptions = APIDocs[subCompName.toLowerCase()].interfaces.values[`${subCompName}PassThroughMethodOptions`];
const objToReplace = subOptions.props.find((opt) => opt.name === 'parent');
objToReplace.type = prop.type;
}
2024-09-13 14:23:04 +00:00
if (!prop.deprecated) {
data.push({
value: i + 1,
label: prop.name,
options: hasSubComp ? subOptions?.props : options?.props,
description: prop.description
});
}
} else {
data.push({
value: i + 1,
label: prop.name,
description: prop.description
});
}
}
return data;
};
2024-05-13 21:48:50 +00:00
export const getStyleOptions = (name) => {
const styleDoc = APIDocs[name.toLowerCase() + 'style'];
const enumValues = styleDoc && styleDoc.enumerations && styleDoc.enumerations.values;
const { members = [] } = enumValues ? enumValues[`${name}Classes`] || {} : {};
2024-05-13 21:48:50 +00:00
let data = [];
for (const member of members) {
2024-05-16 14:05:43 +00:00
const { value, description } = member;
2024-05-13 21:48:50 +00:00
data.push({
class: value.replaceAll('"', ''),
description
});
}
return data;
};
2024-05-23 11:07:36 +00:00
export const getTokenOptions = (name) => {
2024-05-13 21:48:50 +00:00
let data = [];
2025-02-13 10:22:43 +00:00
if (ComponentTokens[name.toLowerCase()]) {
const tokens = ComponentTokens[name.toLowerCase()].tokens;
2024-05-13 21:48:50 +00:00
2025-02-13 10:22:43 +00:00
for (const [_, value] of Object.entries(tokens)) {
data.push({
token: value.token,
variable: value.variable,
description: value.description
});
2024-05-13 21:48:50 +00:00
}
}
return data;
};