@wix/design-system
Version:
@wix/design-system
49 lines • 1.92 kB
JavaScript
export const segmentedToggleDriverFactory = base => {
const findChild = hook => {
if (typeof hook === 'string') {
return base.$(`[data-hook="${hook}"]`);
}
return base.$(`[data-click="segmented-toggle-${hook}"]`);
};
return {
/**
* Selects child by given number (selection begins with 1) or dataHook
* @param {string | number} hook Hook name or index
* @returns { Promise<void>}
*/
selectChild: async (hook) => findChild(hook).click(),
/**
* Returns true if child is selected by given number (selection begins with 1) or dataHook
* @param {string | number} hook Hook name or index
* @returns { Promise<void>}
*/
isSelected: async (hook) => (await findChild(hook).attr('aria-checked')) === 'true',
/**
* Checks whether element is in the DOM
* @returns { Promise<boolean>}
*/
exists: async () => await base.exists(),
/**
* Gets the actual element
* @returns { Promise<any>}
*/
element: async () => await base.getNative(),
/**
* Returns the size applied to segmented toggle
* @returns { Promise<'small' | 'medium'>}
*/
getSize: async () => base.attr('data-size'),
/**
* returns if the segmented toggle is disabled
* @returns { Promise<boolean>}
*/
isDisabled: async () => (await base.$$('button[disabled]').count()) > 0,
/**
* Returns true if child is disabled by given number (selection begins with 1) or dataHook
* @param {string | number} hook Hook name or index
* @returns { Promise<boolean>}
*/
isChildDisabled: async (hook) => (await findChild(hook).attr('disabled')) !== null,
};
};
//# sourceMappingURL=SegmentedToggle.uni.driver.js.map