@shopify/app-bridge-core
Version:
**[Join our team and work on libraries like this one.](https://www.shopify.ca/careers)**
25 lines (22 loc) • 1.01 kB
JavaScript
import { Action, Style, Icon } from '../../actions/Button/index.js';
import { matchesObject, composeSchemas, validate, makeOptional, matchesBoolean, matchesString, matchesEnum } from '../type-validate.js';
import { createActionValidator } from '../utils.js';
const buttonSchema = matchesObject({
disabled: makeOptional(matchesBoolean()),
label: matchesString(),
style: makeOptional(matchesEnum(Style)),
icon: makeOptional(matchesEnum(Icon)),
loading: makeOptional(matchesBoolean()),
plain: makeOptional(matchesBoolean()),
});
const buttonSchemaWithId = composeSchemas(matchesObject({
id: matchesString(),
}), buttonSchema);
function validateProps(props) {
return validate(props, buttonSchema);
}
function validateAction(action) {
const validator = createActionValidator(Action, action.type === Action.UPDATE ? buttonSchema : undefined, true, true);
return validate(action, validator);
}
export { Action, buttonSchema, buttonSchemaWithId, validateAction, validateProps };