UNPKG

styled-components

Version:

Visual primitives for the component age. Use the best bits of ES6 and CSS to style your apps without stress 💅

38 lines (32 loc) • 973 B
// @flow function assertElement(element) { if (!(element instanceof HTMLElement)) { throw new Error( 'Must pass a DOM element to find/findAll(element, styledComponent)"' ) } } function assertStyledComponent(styledComponent) { if ( !( typeof styledComponent === 'function' && typeof styledComponent.styledComponentId === 'string' ) ) { throw new Error( 'Must pass a styled component to find/findAll(element, styledComponent)"' ) } } function find(element /* : Element */, styledComponent /* : Object */) { assertElement(element) assertStyledComponent(styledComponent) return element.querySelector(`.${styledComponent.styledComponentId}`) } function findAll(element /* : Element */, styledComponent /* : Object */) { assertElement(element) assertStyledComponent(styledComponent) return element.querySelectorAll(`.${styledComponent.styledComponentId}`) } exports.find = find exports.findAll = findAll