code
stringlengths
24
2.07M
docstring
stringlengths
25
85.3k
func_name
stringlengths
1
92
language
stringclasses
1 value
repo
stringlengths
5
64
path
stringlengths
4
172
url
stringlengths
44
218
license
stringclasses
7 values
function Column() { return <div />; }
A column is a vertical element of a table that contains data. The Column component is an abstraction that allows us to represent data of the same data type. Both components (Table and Column) are related and should be implemented together. @category DataView
Column
javascript
nexxtway/react-rainbow
src/components/Column/index.js
https://github.com/nexxtway/react-rainbow/blob/master/src/components/Column/index.js
MIT
handlePlusMouseDown = event => { event.preventDefault(); inputRef.current.focus(); const val = getValue(Number(value)); if (val < min) return onChange(getNormalizedValue(min)); return onChange(getNormalizedValue(val + step)); }
CounterInput is a component that lets you enter a number. You can increase and decrease the value using your mouse or by simply typing the number. @category Form
handlePlusMouseDown
javascript
nexxtway/react-rainbow
src/components/CounterInput/index.js
https://github.com/nexxtway/react-rainbow/blob/master/src/components/CounterInput/index.js
MIT
handlePlusMouseDown = event => { event.preventDefault(); inputRef.current.focus(); const val = getValue(Number(value)); if (val < min) return onChange(getNormalizedValue(min)); return onChange(getNormalizedValue(val + step)); }
CounterInput is a component that lets you enter a number. You can increase and decrease the value using your mouse or by simply typing the number. @category Form
handlePlusMouseDown
javascript
nexxtway/react-rainbow
src/components/CounterInput/index.js
https://github.com/nexxtway/react-rainbow/blob/master/src/components/CounterInput/index.js
MIT
handleMinusMouseDown = event => { event.preventDefault(); inputRef.current.focus(); const val = getValue(Number(value)); if (val > max) return onChange(getNormalizedValue(max)); return onChange(getNormalizedValue(val - step)); }
CounterInput is a component that lets you enter a number. You can increase and decrease the value using your mouse or by simply typing the number. @category Form
handleMinusMouseDown
javascript
nexxtway/react-rainbow
src/components/CounterInput/index.js
https://github.com/nexxtway/react-rainbow/blob/master/src/components/CounterInput/index.js
MIT
handleMinusMouseDown = event => { event.preventDefault(); inputRef.current.focus(); const val = getValue(Number(value)); if (val > max) return onChange(getNormalizedValue(max)); return onChange(getNormalizedValue(val - step)); }
CounterInput is a component that lets you enter a number. You can increase and decrease the value using your mouse or by simply typing the number. @category Form
handleMinusMouseDown
javascript
nexxtway/react-rainbow
src/components/CounterInput/index.js
https://github.com/nexxtway/react-rainbow/blob/master/src/components/CounterInput/index.js
MIT
handleEvents = (event, callback) => { if (event.target.value === '') { return callback(); } return callback(Number(event.target.value)); }
CounterInput is a component that lets you enter a number. You can increase and decrease the value using your mouse or by simply typing the number. @category Form
handleEvents
javascript
nexxtway/react-rainbow
src/components/CounterInput/index.js
https://github.com/nexxtway/react-rainbow/blob/master/src/components/CounterInput/index.js
MIT
handleEvents = (event, callback) => { if (event.target.value === '') { return callback(); } return callback(Number(event.target.value)); }
CounterInput is a component that lets you enter a number. You can increase and decrease the value using your mouse or by simply typing the number. @category Form
handleEvents
javascript
nexxtway/react-rainbow
src/components/CounterInput/index.js
https://github.com/nexxtway/react-rainbow/blob/master/src/components/CounterInput/index.js
MIT
constructor(rootElement) { this.rootElement = rootElement; this.modalRootEl = `${rootElement}_modal`; this.calendarRootEl = `${rootElement}_modal_calendar`; }
Create a new PageDatePicker page object. @constructor @param {string} rootElement - The selector of the PageDatePicker root element.
constructor
javascript
nexxtway/react-rainbow
src/components/DatePicker/pageObject/index.js
https://github.com/nexxtway/react-rainbow/blob/master/src/components/DatePicker/pageObject/index.js
MIT
async getValue() { return $(this.rootElement) .$('input[type="text"]') .getValue(); }
Returns the value of the input element. @method @returns {string}
getValue
javascript
nexxtway/react-rainbow
src/components/DatePicker/pageObject/index.js
https://github.com/nexxtway/react-rainbow/blob/master/src/components/DatePicker/pageObject/index.js
MIT
async clickLabel() { await $(this.rootElement) .$('label') .click(); }
Clicks the input label element. @method
clickLabel
javascript
nexxtway/react-rainbow
src/components/DatePicker/pageObject/index.js
https://github.com/nexxtway/react-rainbow/blob/master/src/components/DatePicker/pageObject/index.js
MIT
async clickDay(day) { const calendar = await PageCalendar(this.calendarRootEl); await calendar.clickDay(day); }
Clicks the calendar specific day button element. @method
clickDay
javascript
nexxtway/react-rainbow
src/components/DatePicker/pageObject/index.js
https://github.com/nexxtway/react-rainbow/blob/master/src/components/DatePicker/pageObject/index.js
MIT
async isOpen() { return ( (await $(this.modalRootEl).isDisplayed()) && (await $(this.modalRootEl) .$('h1') .isDisplayed()) && (await $(this.modalRootEl) .$('select') .isDisplayed()) ); }
Returns true when the DatePicker modal is open, false otherwise. @method @returns {bool}
isOpen
javascript
nexxtway/react-rainbow
src/components/DatePicker/pageObject/index.js
https://github.com/nexxtway/react-rainbow/blob/master/src/components/DatePicker/pageObject/index.js
MIT
async hasFocusInput() { return (await $(this.rootElement).$('input[type="text"]')).isFocused(); }
Returns true when the DatePicker has focus. @method @returns {bool}
hasFocusInput
javascript
nexxtway/react-rainbow
src/components/DatePicker/pageObject/index.js
https://github.com/nexxtway/react-rainbow/blob/master/src/components/DatePicker/pageObject/index.js
MIT
async getDate() { return $(this.modalRootEl) .$('h1') .getText(); }
Returns the date displayed on top of the DatePicker. @method @returns {string}
getDate
javascript
nexxtway/react-rainbow
src/components/DatePicker/pageObject/index.js
https://github.com/nexxtway/react-rainbow/blob/master/src/components/DatePicker/pageObject/index.js
MIT
async waitUntilOpen() { await browser.waitUntil(async () => await this.isOpen()); }
Wait until the DatePicker modal is open. @method
waitUntilOpen
javascript
nexxtway/react-rainbow
src/components/DatePicker/pageObject/index.js
https://github.com/nexxtway/react-rainbow/blob/master/src/components/DatePicker/pageObject/index.js
MIT
async waitUntilClose() { await browser.waitUntil(async () => !(await this.isOpen())); }
Wait until the DatePicker modal is closed. @method
waitUntilClose
javascript
nexxtway/react-rainbow
src/components/DatePicker/pageObject/index.js
https://github.com/nexxtway/react-rainbow/blob/master/src/components/DatePicker/pageObject/index.js
MIT
openModal = event => { if (!readOnly) { setIsOpen(true); onClick(event); } }
A DateTimePicker is used to select a day and a time. @category Form
openModal
javascript
nexxtway/react-rainbow
src/components/DateTimePicker/index.js
https://github.com/nexxtway/react-rainbow/blob/master/src/components/DateTimePicker/index.js
MIT
openModal = event => { if (!readOnly) { setIsOpen(true); onClick(event); } }
A DateTimePicker is used to select a day and a time. @category Form
openModal
javascript
nexxtway/react-rainbow
src/components/DateTimePicker/index.js
https://github.com/nexxtway/react-rainbow/blob/master/src/components/DateTimePicker/index.js
MIT
handleKeyDown = ({ keyCode }) => { const shouldOpenModal = (keyCode === ENTER_KEY || keyCode === SPACE_KEY) && !readOnly; if (shouldOpenModal) { setIsOpen(true); } }
A DateTimePicker is used to select a day and a time. @category Form
handleKeyDown
javascript
nexxtway/react-rainbow
src/components/DateTimePicker/index.js
https://github.com/nexxtway/react-rainbow/blob/master/src/components/DateTimePicker/index.js
MIT
handleKeyDown = ({ keyCode }) => { const shouldOpenModal = (keyCode === ENTER_KEY || keyCode === SPACE_KEY) && !readOnly; if (shouldOpenModal) { setIsOpen(true); } }
A DateTimePicker is used to select a day and a time. @category Form
handleKeyDown
javascript
nexxtway/react-rainbow
src/components/DateTimePicker/index.js
https://github.com/nexxtway/react-rainbow/blob/master/src/components/DateTimePicker/index.js
MIT
handleChange = (...args) => { closeModal(); onChange(...args); }
A DateTimePicker is used to select a day and a time. @category Form
handleChange
javascript
nexxtway/react-rainbow
src/components/DateTimePicker/index.js
https://github.com/nexxtway/react-rainbow/blob/master/src/components/DateTimePicker/index.js
MIT
handleChange = (...args) => { closeModal(); onChange(...args); }
A DateTimePicker is used to select a day and a time. @category Form
handleChange
javascript
nexxtway/react-rainbow
src/components/DateTimePicker/index.js
https://github.com/nexxtway/react-rainbow/blob/master/src/components/DateTimePicker/index.js
MIT
constructor(rootElement) { this.rootElement = rootElement; this.modalRootEl = `${rootElement}_modal`; }
Create a new PageDateTimePicker page object. @constructor @param {string} rootElement - The selector of the PageDateTimePicker root element.
constructor
javascript
nexxtway/react-rainbow
src/components/DateTimePicker/pageObject/index.js
https://github.com/nexxtway/react-rainbow/blob/master/src/components/DateTimePicker/pageObject/index.js
MIT
async getTimeValue() { return new PageTimeSelect(this.modalRootEl).getValue(); }
Returns the selected time value. @method @returns {string}
getTimeValue
javascript
nexxtway/react-rainbow
src/components/DateTimePicker/pageObject/index.js
https://github.com/nexxtway/react-rainbow/blob/master/src/components/DateTimePicker/pageObject/index.js
MIT
async getValue() { return $(this.rootElement) .$('input[type="text"]') .getValue(); }
Returns the value of the input element. @method @returns {string}
getValue
javascript
nexxtway/react-rainbow
src/components/DateTimePicker/pageObject/index.js
https://github.com/nexxtway/react-rainbow/blob/master/src/components/DateTimePicker/pageObject/index.js
MIT
async clickLabel() { await $(this.rootElement) .$('label') .click(); }
Clicks the input label element. @method
clickLabel
javascript
nexxtway/react-rainbow
src/components/DateTimePicker/pageObject/index.js
https://github.com/nexxtway/react-rainbow/blob/master/src/components/DateTimePicker/pageObject/index.js
MIT
async clickDay(day) { const calendar = await PageCalendar(this.modalRootEl); await calendar.clickDay(day); }
Clicks the calendar specific day button element. @method
clickDay
javascript
nexxtway/react-rainbow
src/components/DateTimePicker/pageObject/index.js
https://github.com/nexxtway/react-rainbow/blob/master/src/components/DateTimePicker/pageObject/index.js
MIT
async clickOKButton() { await $(this.modalRootEl) .$('button[id="time-picker_ok-button"]') .click(); }
Clicks the OK button element @method
clickOKButton
javascript
nexxtway/react-rainbow
src/components/DateTimePicker/pageObject/index.js
https://github.com/nexxtway/react-rainbow/blob/master/src/components/DateTimePicker/pageObject/index.js
MIT
async clickCancelButton() { await $(this.modalRootEl) .$('button[id="time-picker_cancel-button"]') .click(); }
Clicks the Cancel button element @method
clickCancelButton
javascript
nexxtway/react-rainbow
src/components/DateTimePicker/pageObject/index.js
https://github.com/nexxtway/react-rainbow/blob/master/src/components/DateTimePicker/pageObject/index.js
MIT
async isOpen() { return ( (await $(this.modalRootEl).isDisplayed()) && (await $(this.modalRootEl) .$('button[id="time-picker_ok-button"]') .isDisplayed()) && (await $(this.modalRootEl) .$('button[id="time-picker_cancel-button"]') .isDisplayed()) ); }
Returns true when the picker modal is open, false otherwise. @method @returns {bool}
isOpen
javascript
nexxtway/react-rainbow
src/components/DateTimePicker/pageObject/index.js
https://github.com/nexxtway/react-rainbow/blob/master/src/components/DateTimePicker/pageObject/index.js
MIT
async waitUntilOpen() { await browser.waitUntil(async () => await this.isOpen()); }
Wait until the modal is open. @method
waitUntilOpen
javascript
nexxtway/react-rainbow
src/components/DateTimePicker/pageObject/index.js
https://github.com/nexxtway/react-rainbow/blob/master/src/components/DateTimePicker/pageObject/index.js
MIT
async waitUntilClose() { await browser.waitUntil(async () => !(await this.isOpen())); }
Wait until the modal is closed. @method
waitUntilClose
javascript
nexxtway/react-rainbow
src/components/DateTimePicker/pageObject/index.js
https://github.com/nexxtway/react-rainbow/blob/master/src/components/DateTimePicker/pageObject/index.js
MIT
constructor(rootElement) { this.rootElement = rootElement; }
Create a new PageTimeSelect page object. @constructor @param {string} rootElement - The selector of the PageTimeSelect root element.
constructor
javascript
nexxtway/react-rainbow
src/components/DateTimePicker/pageObject/pageTimeSelect.js
https://github.com/nexxtway/react-rainbow/blob/master/src/components/DateTimePicker/pageObject/pageTimeSelect.js
MIT
async getValue() { const hour = await (await $(this.rootElement).$('input[data-id=hour]')).getValue(); const minutes = await (await $(this.rootElement).$('input[data-id=minutes]')).getValue(); const meridian = await (await $(this.rootElement).$( 'input[aria-label="am-pm selector"]', )).getValue(); return hour && minutes && meridian ? `${hour}:${minutes} ${meridian}` : ''; }
Returns the text representing the current selected time. @method @returns {string}
getValue
javascript
nexxtway/react-rainbow
src/components/DateTimePicker/pageObject/pageTimeSelect.js
https://github.com/nexxtway/react-rainbow/blob/master/src/components/DateTimePicker/pageObject/pageTimeSelect.js
MIT
function Drawer(props) { const { id, isOpen, hideCloseButton, onRequestClose, onOpened, header, footer, size, slideFrom, children, className, style, } = props; const headerId = useUniqueIdentifier('drawer-header'); const contentId = useUniqueIdentifier('drawer-content'); const triggerRef = useRef(null); const drawerRef = useRef(null); const containerRef = useRef(null); const contentRef = useRef(null); const [drawerState, setDrawerState] = useState( isOpen ? DrawerState.OPENED : DrawerState.CLOSED, ); useEffect(() => { const contentElement = contentRef.current; if (isOpen) { CounterManager.increment(); disableBodyScroll(contentElement); triggerRef.current = document.activeElement; setDrawerState(DrawerState.OPENING); } return () => { if (isOpen) { CounterManager.decrement(); if (triggerRef.current) triggerRef.current.focus(); if (!CounterManager.hasModalsOpen()) { enableBodyScroll(contentElement); } clearAllBodyScrollLocks(); setDrawerState(DrawerState.CLOSING); } }; }, [isOpen]); useEffect(() => { if (isOpen && drawerState === DrawerState.OPENED) { drawerRef.current.focus(); onOpened(); } }, [drawerState, isOpen, onOpened]); const onSlideEnd = () => { if (drawerState === DrawerState.OPENING) { setDrawerState(DrawerState.OPENED); } else if (drawerState === DrawerState.CLOSING) { setDrawerState(DrawerState.CLOSED); } }; const closeDrawer = () => onRequestClose(); const handleBackDropClick = useCallback(event => { if (drawerRef.current.contains(event.target)) { return null; } return closeDrawer(); // eslint-disable-next-line react-hooks/exhaustive-deps }, []); useEffect(() => { const node = containerRef.current; if (drawerState === 1) { node.addEventListener('click', handleBackDropClick); } return () => { if (node) { node.removeEventListener('click', handleBackDropClick); } }; }, [drawerState, handleBackDropClick]); const handleKeyPressed = event => { event.stopPropagation(); if (isOpen && event.keyCode === ESCAPE_KEY && containerRef.current.contains(event.target)) { closeDrawer(); } if (event.keyCode === TAB_KEY) { manageTab(drawerRef.current, event); } return null; }; const drawerIsOpen = [DrawerState.OPENING, DrawerState.OPENED].includes(drawerState); if (drawerState !== null && drawerState !== DrawerState.CLOSED) { return createPortal( <StyledBackDrop id={id} role="presentation" ref={containerRef} onKeyDown={handleKeyPressed} > <StyledContainer role="dialog" tabIndex={-1} aria-labelledby={headerId} aria-modal aria-hidden={!drawerIsOpen} aria-describedby={contentId} className={className} isOpen={drawerIsOpen} style={style} size={size} slideFrom={getSlideFrom(slideFrom, 'left')} ref={drawerRef} onAnimationEnd={onSlideEnd} > <Header id={headerId} content={header} /> <RenderIf isTrue={!hideCloseButton}> <StyledCloseButton id="drawer-close-button" icon={<CloseIcon />} title="Hide" onClick={closeDrawer} /> </RenderIf> <StyledContent id={contentId} ref={contentRef}> {children} </StyledContent> <RenderIf isTrue={footer}> <StyledDivider /> <StyledFooter>{footer}</StyledFooter> </RenderIf> </StyledContainer> </StyledBackDrop>, document.body, ); } return <></>; }
Drawers are surfaces containing supplementary content on your app. @category Layout
Drawer
javascript
nexxtway/react-rainbow
src/components/Drawer/index.js
https://github.com/nexxtway/react-rainbow/blob/master/src/components/Drawer/index.js
MIT
onSlideEnd = () => { if (drawerState === DrawerState.OPENING) { setDrawerState(DrawerState.OPENED); } else if (drawerState === DrawerState.CLOSING) { setDrawerState(DrawerState.CLOSED); } }
Drawers are surfaces containing supplementary content on your app. @category Layout
onSlideEnd
javascript
nexxtway/react-rainbow
src/components/Drawer/index.js
https://github.com/nexxtway/react-rainbow/blob/master/src/components/Drawer/index.js
MIT
onSlideEnd = () => { if (drawerState === DrawerState.OPENING) { setDrawerState(DrawerState.OPENED); } else if (drawerState === DrawerState.CLOSING) { setDrawerState(DrawerState.CLOSED); } }
Drawers are surfaces containing supplementary content on your app. @category Layout
onSlideEnd
javascript
nexxtway/react-rainbow
src/components/Drawer/index.js
https://github.com/nexxtway/react-rainbow/blob/master/src/components/Drawer/index.js
MIT
handleKeyPressed = event => { event.stopPropagation(); if (isOpen && event.keyCode === ESCAPE_KEY && containerRef.current.contains(event.target)) { closeDrawer(); } if (event.keyCode === TAB_KEY) { manageTab(drawerRef.current, event); } return null; }
Drawers are surfaces containing supplementary content on your app. @category Layout
handleKeyPressed
javascript
nexxtway/react-rainbow
src/components/Drawer/index.js
https://github.com/nexxtway/react-rainbow/blob/master/src/components/Drawer/index.js
MIT
handleKeyPressed = event => { event.stopPropagation(); if (isOpen && event.keyCode === ESCAPE_KEY && containerRef.current.contains(event.target)) { closeDrawer(); } if (event.keyCode === TAB_KEY) { manageTab(drawerRef.current, event); } return null; }
Drawers are surfaces containing supplementary content on your app. @category Layout
handleKeyPressed
javascript
nexxtway/react-rainbow
src/components/Drawer/index.js
https://github.com/nexxtway/react-rainbow/blob/master/src/components/Drawer/index.js
MIT
function getPointOutsideDrawer(drawerPosition, drawerSize) { const x = drawerPosition.x > 0 ? drawerPosition.x - 2 : drawerSize.width + 2; const y = Math.round(drawerSize.height / 2); return { x, y }; }
Drawer page object class. @class @tutorial drawer
getPointOutsideDrawer
javascript
nexxtway/react-rainbow
src/components/Drawer/pageObject/index.js
https://github.com/nexxtway/react-rainbow/blob/master/src/components/Drawer/pageObject/index.js
MIT
constructor(rootElement) { this.rootElement = rootElement; }
Create a new PageDrawer page object. @constructor @param {string} rootElement - The selector of the PageDrawer root element.
constructor
javascript
nexxtway/react-rainbow
src/components/Drawer/pageObject/index.js
https://github.com/nexxtway/react-rainbow/blob/master/src/components/Drawer/pageObject/index.js
MIT
async clickCloseButton() { await $(this.rootElement) .$('[id="drawer-close-button"]') .click(); }
Clicks the close button element. @method
clickCloseButton
javascript
nexxtway/react-rainbow
src/components/Drawer/pageObject/index.js
https://github.com/nexxtway/react-rainbow/blob/master/src/components/Drawer/pageObject/index.js
MIT
async clickBackDrop() { await $(this.rootElement) .$('[id="drawer-close-button"]') .waitForDisplayed(); const section = await $(this.rootElement).$('section[role="dialog"]'); const { x, y } = getPointOutsideDrawer( await section.getLocation(), await section.getSize(), ); await $(this.rootElement) .$('[id="drawer-close-button"]') .click({ x, y }); }
Clicks the drawer's backdrop element. @method
clickBackDrop
javascript
nexxtway/react-rainbow
src/components/Drawer/pageObject/index.js
https://github.com/nexxtway/react-rainbow/blob/master/src/components/Drawer/pageObject/index.js
MIT
async isOpen() { return ( (await $(this.rootElement).isExisting()) && (await $(this.rootElement) .$('section[role="dialog"]') .isDisplayed()) && (await $(this.rootElement) .$('[id="drawer-close-button"]') .isDisplayed()) ); }
Returns true when the drawer is open, false otherwise. @method @returns {bool}
isOpen
javascript
nexxtway/react-rainbow
src/components/Drawer/pageObject/index.js
https://github.com/nexxtway/react-rainbow/blob/master/src/components/Drawer/pageObject/index.js
MIT
async hasFocusCloseButton() { return $(this.rootElement) .$('[id="drawer-close-button"]') .isFocused(); }
Returns true when the closeButton has focus. @method @returns {bool}
hasFocusCloseButton
javascript
nexxtway/react-rainbow
src/components/Drawer/pageObject/index.js
https://github.com/nexxtway/react-rainbow/blob/master/src/components/Drawer/pageObject/index.js
MIT
async waitUntilOpen() { await browser.pause(1000); await browser.waitUntil(async () => await this.isOpen()); }
Wait until the open transition has finished. @method
waitUntilOpen
javascript
nexxtway/react-rainbow
src/components/Drawer/pageObject/index.js
https://github.com/nexxtway/react-rainbow/blob/master/src/components/Drawer/pageObject/index.js
MIT
async waitUntilClose() { await browser.pause(1000); await browser.waitUntil(async () => !(await $(this.rootElement).isExisting())); }
Wait until the close transition has finished. @method
waitUntilClose
javascript
nexxtway/react-rainbow
src/components/Drawer/pageObject/index.js
https://github.com/nexxtway/react-rainbow/blob/master/src/components/Drawer/pageObject/index.js
MIT
DynamicMenuItem = props => { const { renderIf, disabled, rowData: row, ...rest } = props; const shouldRender = typeof renderIf === 'function' ? renderIf({ row }) : true; const isDisabled = typeof disabled === 'function' ? disabled({ row }) : false; if (shouldRender) { // eslint-disable-next-line react/jsx-props-no-spreading return <MenuItem {...rest} disabled={isDisabled} />; } return null; }
A DynamicMenuItem is a menu item meant to be used in the action column of Table. This component adds two new props that allows to render the item conditionally based on row data. @category DataView
DynamicMenuItem
javascript
nexxtway/react-rainbow
src/components/DynamicMenuItem/index.js
https://github.com/nexxtway/react-rainbow/blob/master/src/components/DynamicMenuItem/index.js
MIT
DynamicMenuItem = props => { const { renderIf, disabled, rowData: row, ...rest } = props; const shouldRender = typeof renderIf === 'function' ? renderIf({ row }) : true; const isDisabled = typeof disabled === 'function' ? disabled({ row }) : false; if (shouldRender) { // eslint-disable-next-line react/jsx-props-no-spreading return <MenuItem {...rest} disabled={isDisabled} />; } return null; }
A DynamicMenuItem is a menu item meant to be used in the action column of Table. This component adds two new props that allows to render the item conditionally based on row data. @category DataView
DynamicMenuItem
javascript
nexxtway/react-rainbow
src/components/DynamicMenuItem/index.js
https://github.com/nexxtway/react-rainbow/blob/master/src/components/DynamicMenuItem/index.js
MIT
function GMap(props) { const { apiKey, ...rest } = props; // eslint-disable-next-line react-hooks/exhaustive-deps const Component = useCallback( scriptLoader(`${googleMapApiUrl}?key=${apiKey}&libraries=places`)(MapComponent), [apiKey], ); // eslint-disable-next-line react/jsx-props-no-spreading return <Component {...rest} />; }
The GMap component is used to find a location.
GMap
javascript
nexxtway/react-rainbow
src/components/GMap/index.js
https://github.com/nexxtway/react-rainbow/blob/master/src/components/GMap/index.js
MIT
function GoogleAddressLookup(props) { const { apiKey, ...rest } = props; // eslint-disable-next-line react-hooks/exhaustive-deps const Component = useCallback( scriptLoader(`${googleMapApiUrl}?key=${apiKey}&libraries=places`)(PlacesLookupComponent), [apiKey], ); // eslint-disable-next-line react/jsx-props-no-spreading return <Component {...rest} />; }
The GoogleAddressLookup component is used to find a location. @category Form
GoogleAddressLookup
javascript
nexxtway/react-rainbow
src/components/GoogleAddressLookup/index.js
https://github.com/nexxtway/react-rainbow/blob/master/src/components/GoogleAddressLookup/index.js
MIT
handleBlur = () => { if (!isClickTooltip.current) { setIsFocused(false); } }
HelpText is a popup that displays information related to an element.
handleBlur
javascript
nexxtway/react-rainbow
src/components/HelpText/index.js
https://github.com/nexxtway/react-rainbow/blob/master/src/components/HelpText/index.js
MIT
handleBlur = () => { if (!isClickTooltip.current) { setIsFocused(false); } }
HelpText is a popup that displays information related to an element.
handleBlur
javascript
nexxtway/react-rainbow
src/components/HelpText/index.js
https://github.com/nexxtway/react-rainbow/blob/master/src/components/HelpText/index.js
MIT
handleButtonMouseLeave = () => { if (!isFocused) { setTimeout(() => { if (!isHoverTooltip.current) closeOverlay(); }, 50); } }
HelpText is a popup that displays information related to an element.
handleButtonMouseLeave
javascript
nexxtway/react-rainbow
src/components/HelpText/index.js
https://github.com/nexxtway/react-rainbow/blob/master/src/components/HelpText/index.js
MIT
handleButtonMouseLeave = () => { if (!isFocused) { setTimeout(() => { if (!isHoverTooltip.current) closeOverlay(); }, 50); } }
HelpText is a popup that displays information related to an element.
handleButtonMouseLeave
javascript
nexxtway/react-rainbow
src/components/HelpText/index.js
https://github.com/nexxtway/react-rainbow/blob/master/src/components/HelpText/index.js
MIT
handleTooltipMouseDown = () => { isClickTooltip.current = true; }
HelpText is a popup that displays information related to an element.
handleTooltipMouseDown
javascript
nexxtway/react-rainbow
src/components/HelpText/index.js
https://github.com/nexxtway/react-rainbow/blob/master/src/components/HelpText/index.js
MIT
handleTooltipMouseDown = () => { isClickTooltip.current = true; }
HelpText is a popup that displays information related to an element.
handleTooltipMouseDown
javascript
nexxtway/react-rainbow
src/components/HelpText/index.js
https://github.com/nexxtway/react-rainbow/blob/master/src/components/HelpText/index.js
MIT
handleTooltipMouseUp = () => { isClickTooltip.current = false; setTimeout(() => triggerRef.current.focus()); }
HelpText is a popup that displays information related to an element.
handleTooltipMouseUp
javascript
nexxtway/react-rainbow
src/components/HelpText/index.js
https://github.com/nexxtway/react-rainbow/blob/master/src/components/HelpText/index.js
MIT
handleTooltipMouseUp = () => { isClickTooltip.current = false; setTimeout(() => triggerRef.current.focus()); }
HelpText is a popup that displays information related to an element.
handleTooltipMouseUp
javascript
nexxtway/react-rainbow
src/components/HelpText/index.js
https://github.com/nexxtway/react-rainbow/blob/master/src/components/HelpText/index.js
MIT
handleTooltipMouseEnter = () => { isHoverTooltip.current = true; }
HelpText is a popup that displays information related to an element.
handleTooltipMouseEnter
javascript
nexxtway/react-rainbow
src/components/HelpText/index.js
https://github.com/nexxtway/react-rainbow/blob/master/src/components/HelpText/index.js
MIT
handleTooltipMouseEnter = () => { isHoverTooltip.current = true; }
HelpText is a popup that displays information related to an element.
handleTooltipMouseEnter
javascript
nexxtway/react-rainbow
src/components/HelpText/index.js
https://github.com/nexxtway/react-rainbow/blob/master/src/components/HelpText/index.js
MIT
handleTooltipMouseLeave = () => { isHoverTooltip.current = false; if (!isFocused) { closeOverlay(); } }
HelpText is a popup that displays information related to an element.
handleTooltipMouseLeave
javascript
nexxtway/react-rainbow
src/components/HelpText/index.js
https://github.com/nexxtway/react-rainbow/blob/master/src/components/HelpText/index.js
MIT
handleTooltipMouseLeave = () => { isHoverTooltip.current = false; if (!isFocused) { closeOverlay(); } }
HelpText is a popup that displays information related to an element.
handleTooltipMouseLeave
javascript
nexxtway/react-rainbow
src/components/HelpText/index.js
https://github.com/nexxtway/react-rainbow/blob/master/src/components/HelpText/index.js
MIT
handleKeyPressed = event => { if (event.keyCode === ESCAPE_KEY) { event.preventDefault(); closeOverlay(); } }
HelpText is a popup that displays information related to an element.
handleKeyPressed
javascript
nexxtway/react-rainbow
src/components/HelpText/index.js
https://github.com/nexxtway/react-rainbow/blob/master/src/components/HelpText/index.js
MIT
handleKeyPressed = event => { if (event.keyCode === ESCAPE_KEY) { event.preventDefault(); closeOverlay(); } }
HelpText is a popup that displays information related to an element.
handleKeyPressed
javascript
nexxtway/react-rainbow
src/components/HelpText/index.js
https://github.com/nexxtway/react-rainbow/blob/master/src/components/HelpText/index.js
MIT
function HighlightedText(props) { const { style, className, parts, hitComponent, textComponent, isInline } = props; const finalHitContainer = hitComponent || DefaultHitContainer; const finalTextContainer = textComponent || DefaultTextContainer; return ( <HighlighContainer className={className} style={style} isInline={isInline}> <HitText parts={parts} hitComponent={finalHitContainer} textComponent={finalTextContainer} /> </HighlighContainer> ); }
HighlightedText is a component that highlights a part of a text.
HighlightedText
javascript
nexxtway/react-rainbow
src/components/HighlightedText/index.js
https://github.com/nexxtway/react-rainbow/blob/master/src/components/HighlightedText/index.js
MIT
constructor(props) { super(props); this.inputRef = React.createRef(); }
Text inputs are used for freeform data entry. @category Form
constructor
javascript
nexxtway/react-rainbow
src/components/Input/index.js
https://github.com/nexxtway/react-rainbow/blob/master/src/components/Input/index.js
MIT
render() { const { type } = this.props; if (type === 'radio') { return <InputRadio ref={this.inputRef} {...this.props} />; } if (type === 'checkbox') { return <InputCheckbox ref={this.inputRef} {...this.props} />; } return <InputBase ref={this.inputRef} {...this.props} />; }
Sets blur on the element. @public
render
javascript
nexxtway/react-rainbow
src/components/Input/index.js
https://github.com/nexxtway/react-rainbow/blob/master/src/components/Input/index.js
MIT
render() { const { className, style, value, label, error, placeholder, onChange, disabled, readOnly, tabIndex, onFocus, onBlur, onClick, onKeyDown, type, max, min, step, maxLength, minLength, pattern, icon, bottomHelpText, required, id, autoComplete, name, labelAlignment, hideLabel, isBare, isCentered, iconPosition, variant, size, valueAlignment, borderRadius, } = this.props; const isReadOnly = !!(!disabled && readOnly); const isPassword = type === 'password'; return ( <StyledContainer id={id} className={className} style={style}> <Label label={label} labelAlignment={labelAlignment} hideLabel={hideLabel} required={required} inputId={this.inputId} readOnly={isReadOnly} id={this.getInlineTextLabelId()} size={size} /> <RelativeElement> <RenderIf isTrue={icon}> <StyledIconContainer iconPosition={iconPosition} readOnly={readOnly} error={error} size={size} > {icon} </StyledIconContainer> </RenderIf> <StyledInput id={this.inputId} name={name} type={this.getInputType()} value={value} placeholder={placeholder} onChange={onChange} tabIndex={tabIndex} onFocus={onFocus} onBlur={onBlur} onClick={onClick} onKeyDown={onKeyDown} disabled={disabled} readOnly={readOnly} required={required} max={max} min={min} step={step} maxLength={maxLength} minLength={minLength} pattern={pattern} autoComplete={autoComplete} aria-labelledby={this.getInlineTextLabelId()} aria-describedby={this.getErrorMessageId()} ref={this.inputRef} isBare={isBare} valueAlignment={getValueAlignment({ valueAlignment, isCentered })} iconPosition={iconPosition} icon={icon} error={error} variant={variant} size={size} borderRadius={borderRadius} /> <RenderIf isTrue={isPassword}> <TogglePasswordButton icon={this.getToggleButtonIcon()} onClick={this.handlePasswordToggle} size={size} /> </RenderIf> </RelativeElement> <RenderIf isTrue={bottomHelpText}> <HelpText alignSelf="center">{bottomHelpText}</HelpText> </RenderIf> <RenderIf isTrue={error}> <ErrorText alignSelf="center" id={this.getErrorMessageId()}> {error} </ErrorText> </RenderIf> </StyledContainer> ); }
Sets blur on the element. @public
render
javascript
nexxtway/react-rainbow
src/components/Input/inputBase/index.js
https://github.com/nexxtway/react-rainbow/blob/master/src/components/Input/inputBase/index.js
MIT
render() { const { name, value, onChange, tabIndex, onFocus, onBlur, onClick, onKeyDown, disabled, checked, ariaLabelledBy, ariaDescribedBy, error, label, hideLabel, } = this.props; return ( <StyledContainer data-id="input-checkbox_container"> <StyledCheckboxInput as="input" id={this.inputId} name={name} type="checkbox" value={value} onChange={onChange} tabIndex={tabIndex} onFocus={onFocus} onBlur={onBlur} onClick={onClick} onKeyDown={onKeyDown} disabled={disabled} checked={checked} aria-labelledby={ariaLabelledBy} aria-describedby={ariaDescribedBy} ref={this.inputRef} error={error} /> <Label label={label} hideLabel={hideLabel} disabled={disabled} inputId={this.inputId} id={ariaLabelledBy} /> </StyledContainer> ); }
Sets blur on the element. @public
render
javascript
nexxtway/react-rainbow
src/components/Input/inputCheckbox/checkbox.js
https://github.com/nexxtway/react-rainbow/blob/master/src/components/Input/inputCheckbox/checkbox.js
MIT
render() { const { className, style, value, onChange, label, error, disabled, tabIndex, onFocus, onBlur, onClick, onKeyDown, bottomHelpText, id, name, checked, hideLabel, } = this.props; const errorMessageId = this.getErrorMessageId(); return ( <StyledContainer id={id} className={className} style={style}> <Checkbox name={name} value={value} onChange={onChange} tabIndex={tabIndex} onFocus={onFocus} onBlur={onBlur} onClick={onClick} onKeyDown={onKeyDown} disabled={disabled} checked={checked} ariaLabelledBy={this.getInlineTextLabelId()} ariaDescribedBy={errorMessageId} ref={this.inputRef} error={error} label={label} hideLabel={hideLabel} /> <RenderIf isTrue={bottomHelpText}> <HelpText alignSelf="flex-start">{bottomHelpText}</HelpText> </RenderIf> <RenderIf isTrue={error}> <ErrorText alignSelf="flex-start" id={errorMessageId}> {error} </ErrorText> </RenderIf> </StyledContainer> ); }
Sets blur on the element. @public
render
javascript
nexxtway/react-rainbow
src/components/Input/inputCheckbox/index.js
https://github.com/nexxtway/react-rainbow/blob/master/src/components/Input/inputCheckbox/index.js
MIT
render() { const { className, style, value, onChange, label, error, disabled, tabIndex, onFocus, onBlur, onClick, onKeyDown, bottomHelpText, id, name, checked, hideLabel, } = this.props; const errorMessageId = this.getErrorMessageId(); return ( <StyledContainer id={id} className={className} style={style}> <Radio name={name} value={value} onChange={onChange} tabIndex={tabIndex} onFocus={onFocus} onBlur={onBlur} onClick={onClick} onKeyDown={onKeyDown} disabled={disabled} checked={checked} ariaLabelledBy={this.getInlineTextLabelId()} ariaDescribedBy={errorMessageId} ref={this.inputRef} error={error} label={label} hideLabel={hideLabel} /> <RenderIf isTrue={bottomHelpText}> <HelpText alignSelf="flex-start">{bottomHelpText}</HelpText> </RenderIf> <RenderIf isTrue={error}> <ErrorText alignSelf="flex-start" id={errorMessageId}> {error} </ErrorText> </RenderIf> </StyledContainer> ); }
Sets blur on the element. @public
render
javascript
nexxtway/react-rainbow
src/components/Input/inputRadio/index.js
https://github.com/nexxtway/react-rainbow/blob/master/src/components/Input/inputRadio/index.js
MIT
render() { const { name, value, onChange, tabIndex, onFocus, onBlur, onClick, onKeyDown, disabled, checked, ariaLabelledBy, ariaDescribedBy, error, label, hideLabel, } = this.props; return ( <StyledContainer data-id="input-radio_container"> <StyledRadioInput as="input" id={this.inputId} name={name} type="radio" value={value} onChange={onChange} tabIndex={tabIndex} onFocus={onFocus} onBlur={onBlur} onClick={onClick} onKeyDown={onKeyDown} disabled={disabled} checked={checked} aria-labelledby={ariaLabelledBy} aria-describedby={ariaDescribedBy} ref={this.inputRef} error={error} /> <Label label={label} hideLabel={hideLabel} disabled={disabled} inputId={this.inputId} id={ariaLabelledBy} /> </StyledContainer> ); }
Sets blur on the element. @public
render
javascript
nexxtway/react-rainbow
src/components/Input/inputRadio/radio.js
https://github.com/nexxtway/react-rainbow/blob/master/src/components/Input/inputRadio/radio.js
MIT
constructor(rootElement) { this.rootElement = rootElement; }
Create a new Input page object. @constructor @param {string} rootElement - The selector of the Input root element.
constructor
javascript
nexxtway/react-rainbow
src/components/Input/pageObject/index.js
https://github.com/nexxtway/react-rainbow/blob/master/src/components/Input/pageObject/index.js
MIT
async hasFocusInput() { return $(this.rootElement) .$('input') .isFocused(); }
Returns true when the input element has focus. @method @returns {bool}
hasFocusInput
javascript
nexxtway/react-rainbow
src/components/Input/pageObject/index.js
https://github.com/nexxtway/react-rainbow/blob/master/src/components/Input/pageObject/index.js
MIT
async setValue(value) { await $(this.rootElement) .$('input') .setValue(value); }
Type in the input element. @method @param {string} value - The value to type in the input element.
setValue
javascript
nexxtway/react-rainbow
src/components/Input/pageObject/index.js
https://github.com/nexxtway/react-rainbow/blob/master/src/components/Input/pageObject/index.js
MIT
async getValue() { return $(this.rootElement) .$('input') .getValue(); }
Get the value typed in the input element. @method @returns {string}
getValue
javascript
nexxtway/react-rainbow
src/components/Input/pageObject/index.js
https://github.com/nexxtway/react-rainbow/blob/master/src/components/Input/pageObject/index.js
MIT
renderInput() { const { props } = this; const { readOnly, isCentered, valueAlignment } = props; const alignment = getValueAlignment({ valueAlignment, isCentered }); if (readOnly) { return ( <StyledReadonlyInput // eslint-disable-next-line react/jsx-props-no-spreading {...props} id={this.inputId} readOnly aria-labelledby={this.getInlineTextLabelId()} aria-describedby={this.getErrorMessageId()} autoComplete="off" valueAlignment={alignment} ref={this.inputRef} /> ); } return ( <StyledPickerInput // eslint-disable-next-line react/jsx-props-no-spreading {...props} id={this.inputId} readOnly aria-labelledby={this.getInlineTextLabelId()} aria-describedby={this.getErrorMessageId()} autoComplete="off" valueAlignment={alignment} ref={this.inputRef} /> ); }
Sets blur on the element. @public
renderInput
javascript
nexxtway/react-rainbow
src/components/Input/pickerInput/index.js
https://github.com/nexxtway/react-rainbow/blob/master/src/components/Input/pickerInput/index.js
MIT
render() { const { className, style, label, error, readOnly, icon, bottomHelpText, required, id, hideLabel, labelAlignment, iconPosition, size, } = this.props; return ( <StyledContainer id={id} className={className} style={style} readOnly={readOnly}> <Label label={label} labelAlignment={labelAlignment} hideLabel={hideLabel} required={required} inputId={this.inputId} readOnly={readOnly} id={this.getInlineTextLabelId()} size={size} /> <RelativeElement> <RenderIf isTrue={icon}> <StyledIconContainer iconPosition={iconPosition} readOnly={readOnly} error={error} size={size} > {icon} </StyledIconContainer> </RenderIf> {this.renderInput()} </RelativeElement> <RenderIf isTrue={bottomHelpText}> <HelpText alignSelf="center">{bottomHelpText}</HelpText> </RenderIf> <RenderIf isTrue={error}> <ErrorText alignSelf="center" id={this.getErrorMessageId()}> {error} </ErrorText> </RenderIf> </StyledContainer> ); }
Sets blur on the element. @public
render
javascript
nexxtway/react-rainbow
src/components/Input/pickerInput/index.js
https://github.com/nexxtway/react-rainbow/blob/master/src/components/Input/pickerInput/index.js
MIT
constructor(rootElement) { this.rootElement = rootElement; }
Create a new PageInternalDropdown page object. @constructor @param {string} rootElement - The selector of the PageInternalDropdown root element.
constructor
javascript
nexxtway/react-rainbow
src/components/InternalDropdown/pageObject/index.js
https://github.com/nexxtway/react-rainbow/blob/master/src/components/InternalDropdown/pageObject/index.js
MIT
async hoverScrollUpArrow() { const upArrow = await $(this.rootElement).$('[data-id="internal-dropdown-arrow-up"]'); await upArrow.scrollIntoView(); return upArrow.moveTo(); }
It moves the pointer over the menu scroll up arrow @method
hoverScrollUpArrow
javascript
nexxtway/react-rainbow
src/components/InternalDropdown/pageObject/index.js
https://github.com/nexxtway/react-rainbow/blob/master/src/components/InternalDropdown/pageObject/index.js
MIT
async hoverScrollDownArrow() { const downArrow = await $(this.rootElement).$('[data-id="internal-dropdown-arrow-down"]'); await downArrow.scrollIntoView(); return downArrow.moveTo(); }
It moves the pointer over the menu scroll down arrow @method
hoverScrollDownArrow
javascript
nexxtway/react-rainbow
src/components/InternalDropdown/pageObject/index.js
https://github.com/nexxtway/react-rainbow/blob/master/src/components/InternalDropdown/pageObject/index.js
MIT
async getOptionsLength() { return (await $(this.rootElement).$$('li[data-selected="false"]')).length; }
Get the number of registered options. @method @returns {number}
getOptionsLength
javascript
nexxtway/react-rainbow
src/components/InternalDropdown/pageObject/index.js
https://github.com/nexxtway/react-rainbow/blob/master/src/components/InternalDropdown/pageObject/index.js
MIT
async getOption(optionIndex) { const activeOptions = await $(this.rootElement).$$('li[data-selected="false"]'); const option = activeOptions[optionIndex]; if (option && !option.error) { return new PageOption(option, await this[privateGetMenuBoundsRect]()); } return null; }
Returns a new Option page object of the element in item position. @method @param {number} optionIndex - The base 0 index of the Option.
getOption
javascript
nexxtway/react-rainbow
src/components/InternalDropdown/pageObject/index.js
https://github.com/nexxtway/react-rainbow/blob/master/src/components/InternalDropdown/pageObject/index.js
MIT
async arrowDownExists() { return $(this.rootElement) .$('[data-id="internal-dropdown-arrow-down"]') .isExisting(); }
Returns true when the arrow to scroll down exits, false otherwise. @method @returns {bool}
arrowDownExists
javascript
nexxtway/react-rainbow
src/components/InternalDropdown/pageObject/index.js
https://github.com/nexxtway/react-rainbow/blob/master/src/components/InternalDropdown/pageObject/index.js
MIT
async arrowUpExists() { return $(this.rootElement) .$('[data-id="internal-dropdown-arrow-up"]') .isExisting(); }
Returns true when the arrow to scroll down exits, false otherwise. @method @returns {bool}
arrowUpExists
javascript
nexxtway/react-rainbow
src/components/InternalDropdown/pageObject/index.js
https://github.com/nexxtway/react-rainbow/blob/master/src/components/InternalDropdown/pageObject/index.js
MIT
async emptyMessageExist() { return $(this.rootElement) .$('[data-id="internal-dropdown-empty-message"]') .isExisting(); }
Returns true when the search no results found, false otherwise. @method @returns {bool}
emptyMessageExist
javascript
nexxtway/react-rainbow
src/components/InternalDropdown/pageObject/index.js
https://github.com/nexxtway/react-rainbow/blob/master/src/components/InternalDropdown/pageObject/index.js
MIT
async isLoading() { return $(this.rootElement) .$('ul[role="presentation"] > div > div') .isExisting(); }
Returns true when loading indicator is visible. @method @returns {bool}
isLoading
javascript
nexxtway/react-rainbow
src/components/InternalDropdown/pageObject/index.js
https://github.com/nexxtway/react-rainbow/blob/master/src/components/InternalDropdown/pageObject/index.js
MIT
async setQuery(value) { await $(this.rootElement) .$('input[type="search"]') .setValue(value); }
Type in the input element. @method @param {string} value - The value to type in the input element.
setQuery
javascript
nexxtway/react-rainbow
src/components/InternalDropdown/pageObject/index.js
https://github.com/nexxtway/react-rainbow/blob/master/src/components/InternalDropdown/pageObject/index.js
MIT
InternalOverlay = props => { const { render: ContentComponent, isVisible, triggerElementRef, positionResolver, onOpened, children, keepScrollEnabled, } = props; const containerRef = useRef(); const [contentMeta, updateContentMeta] = useState(false); const shouldOpen = isVisible && contentMeta; useEffect(() => { if (shouldOpen) { onOpened(); } // eslint-disable-next-line react-hooks/exhaustive-deps }, [shouldOpen]); const shouldDisableScroll = shouldOpen && !keepScrollEnabled; useDisableScroll(shouldDisableScroll); // eslint-disable-next-line react-hooks/exhaustive-deps useIsomorphicLayoutEffect(() => { if (contentMeta && containerRef.current) { const { width, height } = containerRef.current.getBoundingClientRect(); if (width !== contentMeta.width || height !== contentMeta.height) { updateContentMeta({ width, height }); } } }); if (isVisible) { const content = children || <ContentComponent />; if (contentMeta) { const triggerMeta = resolveTriggerMeta(triggerElementRef); const viewportMeta = resolveViewportMeta(); const position = resolvePosition({ triggerMeta, contentMeta, viewportMeta, positionResolver, }); return createPortal( <Container position={position} ref={containerRef}> {content} </Container>, document.body, ); } return ( <ContentMetaResolver component={ContentComponent} onResolved={updateContentMeta}> {children} </ContentMetaResolver> ); } return null; }
This component implements the positioning of a component (inserted in the DOM at the body level) based on a trigger DOM element. By the way of example, you can think of the use case of a Menu Options, Tooltip, Popup that should be floating on top of all the elements and it should be correctly positioned based on the component/element that triggers the show/open action. @category Internal
InternalOverlay
javascript
nexxtway/react-rainbow
src/components/InternalOverlay/index.js
https://github.com/nexxtway/react-rainbow/blob/master/src/components/InternalOverlay/index.js
MIT
InternalOverlay = props => { const { render: ContentComponent, isVisible, triggerElementRef, positionResolver, onOpened, children, keepScrollEnabled, } = props; const containerRef = useRef(); const [contentMeta, updateContentMeta] = useState(false); const shouldOpen = isVisible && contentMeta; useEffect(() => { if (shouldOpen) { onOpened(); } // eslint-disable-next-line react-hooks/exhaustive-deps }, [shouldOpen]); const shouldDisableScroll = shouldOpen && !keepScrollEnabled; useDisableScroll(shouldDisableScroll); // eslint-disable-next-line react-hooks/exhaustive-deps useIsomorphicLayoutEffect(() => { if (contentMeta && containerRef.current) { const { width, height } = containerRef.current.getBoundingClientRect(); if (width !== contentMeta.width || height !== contentMeta.height) { updateContentMeta({ width, height }); } } }); if (isVisible) { const content = children || <ContentComponent />; if (contentMeta) { const triggerMeta = resolveTriggerMeta(triggerElementRef); const viewportMeta = resolveViewportMeta(); const position = resolvePosition({ triggerMeta, contentMeta, viewportMeta, positionResolver, }); return createPortal( <Container position={position} ref={containerRef}> {content} </Container>, document.body, ); } return ( <ContentMetaResolver component={ContentComponent} onResolved={updateContentMeta}> {children} </ContentMetaResolver> ); } return null; }
This component implements the positioning of a component (inserted in the DOM at the body level) based on a trigger DOM element. By the way of example, you can think of the use case of a Menu Options, Tooltip, Popup that should be floating on top of all the elements and it should be correctly positioned based on the component/element that triggers the show/open action. @category Internal
InternalOverlay
javascript
nexxtway/react-rainbow
src/components/InternalOverlay/index.js
https://github.com/nexxtway/react-rainbow/blob/master/src/components/InternalOverlay/index.js
MIT
constructor(rootElement) { this.rootElement = rootElement; }
Create a nre InternalOverlay page object @constructor @param {string} rootElement
constructor
javascript
nexxtway/react-rainbow
src/components/InternalOverlay/pageObject/index.js
https://github.com/nexxtway/react-rainbow/blob/master/src/components/InternalOverlay/pageObject/index.js
MIT
handleOpen = () => { const triggerRect = resolveElement(triggerElementRef).getBoundingClientRect(); const tooltipRect = tooltipRef.current.getBoundingClientRect(); if (tooltipRect.bottom < triggerRect.top) { setPos('top'); } else if (tooltipRect.top > triggerRect.bottom) { setPos('bottom'); } else if (tooltipRect.right < triggerRect.left) { setPos('left'); } else if (tooltipRect.left > triggerRect.right) { setPos('right'); } else { setPos('floating'); } }
A Tooltip is a small piece of contextual information about an element on the screen, which is displayed when a user hovers or focuses on the element it is describing. @category Internal
handleOpen
javascript
nexxtway/react-rainbow
src/components/InternalTooltip/index.js
https://github.com/nexxtway/react-rainbow/blob/master/src/components/InternalTooltip/index.js
MIT
handleOpen = () => { const triggerRect = resolveElement(triggerElementRef).getBoundingClientRect(); const tooltipRect = tooltipRef.current.getBoundingClientRect(); if (tooltipRect.bottom < triggerRect.top) { setPos('top'); } else if (tooltipRect.top > triggerRect.bottom) { setPos('bottom'); } else if (tooltipRect.right < triggerRect.left) { setPos('left'); } else if (tooltipRect.left > triggerRect.right) { setPos('right'); } else { setPos('floating'); } }
A Tooltip is a small piece of contextual information about an element on the screen, which is displayed when a user hovers or focuses on the element it is describing. @category Internal
handleOpen
javascript
nexxtway/react-rainbow
src/components/InternalTooltip/index.js
https://github.com/nexxtway/react-rainbow/blob/master/src/components/InternalTooltip/index.js
MIT
LoadingShape = props => { const { className, style, shape, variant } = props; const shapeRef = useRef(); const isImage = variant === 'image'; const isAvatar = variant === 'avatar'; useEffect(() => { const element = shapeRef.current; if (shape === 'square' || shape === 'circle') { element.style.width = `${element.offsetHeight}px`; } else { element.style.width = '100%'; } }); return ( <StyledShapeContainer className={className} style={style}> <StyledLoadingShape shape={shape} variant={variant} ref={shapeRef}> <RenderIf isTrue={isImage}> <StyledImageIcon shape={shape} /> </RenderIf> <RenderIf isTrue={isAvatar}> <StyledAvatarIcon shape={shape} /> </RenderIf> </StyledLoadingShape> </StyledShapeContainer> ); }
LoadingShape can be used to display a placeholder where content is being loaded asynchronously.
LoadingShape
javascript
nexxtway/react-rainbow
src/components/LoadingShape/index.js
https://github.com/nexxtway/react-rainbow/blob/master/src/components/LoadingShape/index.js
MIT
LoadingShape = props => { const { className, style, shape, variant } = props; const shapeRef = useRef(); const isImage = variant === 'image'; const isAvatar = variant === 'avatar'; useEffect(() => { const element = shapeRef.current; if (shape === 'square' || shape === 'circle') { element.style.width = `${element.offsetHeight}px`; } else { element.style.width = '100%'; } }); return ( <StyledShapeContainer className={className} style={style}> <StyledLoadingShape shape={shape} variant={variant} ref={shapeRef}> <RenderIf isTrue={isImage}> <StyledImageIcon shape={shape} /> </RenderIf> <RenderIf isTrue={isAvatar}> <StyledAvatarIcon shape={shape} /> </RenderIf> </StyledLoadingShape> </StyledShapeContainer> ); }
LoadingShape can be used to display a placeholder where content is being loaded asynchronously.
LoadingShape
javascript
nexxtway/react-rainbow
src/components/LoadingShape/index.js
https://github.com/nexxtway/react-rainbow/blob/master/src/components/LoadingShape/index.js
MIT
constructor(props) { super(props); const normalizedOptions = getNormalizedOptions(props.options || []); this.state = { searchValue: '', isOpen: false, isFocused: false, options: normalizedOptions, focusedItemIndex: getInitialFocusedIndex( normalizedOptions, props.preferredSelectedOption, ), showScrollUpArrow: undefined, showScrollDownArrow: undefined, }; this.inputId = uniqueId('lookup-input'); this.listboxId = uniqueId('lookup-listbox'); this.errorMessageId = uniqueId('error-message'); this.containerRef = React.createRef(); this.inputRef = React.createRef(); this.menuRef = React.createRef(); this.handleSearch = this.handleSearch.bind(this); this.clearInput = this.clearInput.bind(this); this.handleChange = this.handleChange.bind(this); this.handleFocus = this.handleFocus.bind(this); this.handleRemoveValue = this.handleRemoveValue.bind(this); this.handleBlur = this.handleBlur.bind(this); this.handleHover = this.handleHover.bind(this); this.handleKeyDown = this.handleKeyDown.bind(this); this.handleKeyUpPressed = this.handleKeyUpPressed.bind(this); this.handleKeyDownPressed = this.handleKeyDownPressed.bind(this); this.handleKeyEnterPressed = this.handleKeyEnterPressed.bind(this); this.keyHandlerMap = { [UP_KEY]: this.handleKeyUpPressed, [DOWN_KEY]: this.handleKeyDownPressed, [ENTER_KEY]: this.handleKeyEnterPressed, }; this.handleScrollDownArrowHover = this.handleScrollDownArrowHover.bind(this); this.handleScrollUpArrowHover = this.handleScrollUpArrowHover.bind(this); this.stopArrowScoll = this.stopArrowScoll.bind(this); this.updateScrollingArrows = this.updateScrollingArrows.bind(this); this.handleWindowScroll = this.handleWindowScroll.bind(this); this.handleOverlayOpened = this.handleOverlayOpened.bind(this); this.handleClick = this.handleClick.bind(this); this.windowScrolling = new WindowScrolling(); }
A Lookup is an autocomplete text input that will search against a database object, it is enhanced by a panel of suggested options. @category Form
constructor
javascript
nexxtway/react-rainbow
src/components/Lookup/index.js
https://github.com/nexxtway/react-rainbow/blob/master/src/components/Lookup/index.js
MIT
componentDidUpdate(prevProps, prevState) { const { options: prevOptions, preferredSelectedOption: prevPreferredSelectedOption, } = prevProps; const { options, preferredSelectedOption } = this.props; if (prevOptions !== options) { const normalizedOptions = getNormalizedOptions(options); this.setState({ options: normalizedOptions, focusedItemIndex: getInitialFocusedIndex( normalizedOptions, preferredSelectedOption, ), isOpen: this.isLookupOpen(), }); } if (prevPreferredSelectedOption !== preferredSelectedOption) { const { options: currentOptions } = this.state; this.setState({ focusedItemIndex: getInitialFocusedIndex(currentOptions, preferredSelectedOption), isOpen: this.isLookupOpen(), }); } const { isOpen: wasOpen } = prevState; const { isOpen } = this.state; if (!wasOpen && isOpen && this.menuRef.current !== null) { this.updateScrollingArrows(); } if (!this.isLookupOpen()) this.windowScrolling.stopListening(); }
A Lookup is an autocomplete text input that will search against a database object, it is enhanced by a panel of suggested options. @category Form
componentDidUpdate
javascript
nexxtway/react-rainbow
src/components/Lookup/index.js
https://github.com/nexxtway/react-rainbow/blob/master/src/components/Lookup/index.js
MIT
getValue() { const { value } = this.props; if (typeof value === 'object' && !Array.isArray(value)) { return value; } return undefined; }
A Lookup is an autocomplete text input that will search against a database object, it is enhanced by a panel of suggested options. @category Form
getValue
javascript
nexxtway/react-rainbow
src/components/Lookup/index.js
https://github.com/nexxtway/react-rainbow/blob/master/src/components/Lookup/index.js
MIT
getErrorMessageId() { const { error } = this.props; if (error) { return this.errorMessageId; } return undefined; }
A Lookup is an autocomplete text input that will search against a database object, it is enhanced by a panel of suggested options. @category Form
getErrorMessageId
javascript
nexxtway/react-rainbow
src/components/Lookup/index.js
https://github.com/nexxtway/react-rainbow/blob/master/src/components/Lookup/index.js
MIT