@workday/canvas-kit-react
Version:
The parent module that contains all Workday Canvas Kit React components
50 lines (49 loc) • 1.91 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.useDisclosureModel = void 0;
const react_1 = __importDefault(require("react"));
const common_1 = require("@workday/canvas-kit-react/common");
exports.useDisclosureModel = (0, common_1.createModelHook)({
defaultConfig: {
/** ID reference of the list. Children ids can be derived from this id */
id: '',
/**
* The initial visibility of the disclosed content
* @default 'hidden'
*/
initialVisibility: 'hidden',
},
})(config => {
const id = (0, common_1.useUniqueId)(config.id);
const [visibility, setVisibility] = react_1.default.useState(config.initialVisibility || 'hidden');
const state = {
/** ID reference of the list. Children ids can be derived from this id */
id,
/**
* Visibility state of the disclosed content. Models are allowed to extend the states to fit
* their needs, so if you need to consistently determine "not hidden", use
* `visibility !== 'hidden'` rather than `visibility === 'visible'`
*/
visibility,
};
const events = {
/**
* Start showing the disclosed content. If a DOM event triggered this event, the event data will
* be passed along. This data can be used by guards and callbacks.
*/
show(event) {
setVisibility('visible');
},
/**
* Start hiding this disclosed content. If a DOM event triggered this event, the event data will
* be passed along. This data can be used by guards and callbacks.
*/
hide(event) {
setVisibility('hidden');
},
};
return { state, events };
});