Best JavaScript code snippet using playwright-internal
AutoRotatingCrousel.js
Source:AutoRotatingCrousel.js
1import React, { Component } from "react";2import PropTypes from "prop-types";3import Button from "@material-ui/core/Button";4import Paper from "@material-ui/core/Paper";5import { grey } from "@material-ui/core/colors";6import withStyles from "@material-ui/core/styles/withStyles";7import { duration } from "@material-ui/core/styles/transitions";8import Fab from "@material-ui/core/Fab";9import ArrowBackIcon from "@material-ui/icons/ArrowBack";10import ArrowForwardIcon from "@material-ui/icons/ArrowForward";11import Fade from "@material-ui/core/Fade";12import Dots from "material-ui-dots";13import classNames from "classnames";14import Carousel from "./SwipableCarouselView";15import { modulo } from "./util";16const styles = {17 root: {18 "& > *:focus": {19 outline: "none",20 border: "none",21 },22 },23 content: {24 // display: "inlineBlock",25 margin: "auto",26 width: "100%",27 maxWidth: "100%",28 height: "600px",29 maxHeight: 800,30 },31 contentMobile: {32 // marginTop: "auto",33 width: "100%",34 height: "500px",35 maxWidth: "initial",36 maxHeight: "500px",37 "& > $carouselWrapper": {38 borderRadius: 0,39 },40 },41 arrow: {42 width: 48,43 height: 48,44 position: "absolute",45 top: "calc((100% - 96px) / 2 + 24px)",46 },47 arrowLeft: {48 left: -96,49 },50 arrowRight: {51 right: -96,52 },53 arrowIcon: {54 color: grey[700],55 },56 carouselWrapper: {57 overflow: "hidden",58 // borderRadius: 14,59 transform: "scale(1.0)",60 background: "transparent",61 height: "100%",62 width: "100%",63 },64 dots: {65 paddingTop: 8,66 margin: "0 auto",67 },68 dotsMobile: {69 paddingTop: 0,70 },71 dotsMobileLandscape: {72 paddingTop: 20,73 },74 footer: {75 marginTop: -80,76 marginBotoom: "10px",77 width: "100%",78 position: "relative",79 textAlign: "center",80 },81 footerMobile: {82 marginTop: -112,83 },84 footerMobileLandscape: {85 marginTop: -3,86 transform: "translateY(-30vh)",87 display: "inline-block",88 width: "auto",89 },90 slide: {91 width: "100%",92 height: "100%",93 },94 slideMobile: {95 width: "100%",96 height: "100%",97 },98 carousel: {99 height: "100%",100 },101 carouselContainer: {102 height: "100%",103 },104 closed: {},105};106class AutoRotatingCarousel extends Component {107 state = {108 slideIndex: 0,109 };110 handleContentClick = (e) => e.stopPropagation() || e.preventDefault();111 handleChange = (slideIndex) => {112 this.setState(113 {114 slideIndex,115 },116 this.onChange(slideIndex)117 );118 };119 decreaseIndex() {120 const slideIndex = this.state.slideIndex - 1;121 this.setState(122 {123 slideIndex,124 },125 this.onChange(slideIndex)126 );127 }128 increaseIndex() {129 const slideIndex = this.state.slideIndex + 1;130 this.setState(131 {132 slideIndex,133 },134 this.onChange(slideIndex)135 );136 }137 onChange(slideIndex) {138 if (this.props.onChange) {139 this.props.onChange(modulo(slideIndex, this.props.children.length));140 }141 }142 render() {143 const {144 autoplay,145 ButtonProps,146 children,147 classes,148 containerStyle,149 hideArrows,150 interval,151 label,152 landscape: landscapeProp,153 mobile,154 ModalProps,155 open,156 onClose,157 onStart,158 } = this.props;159 const landscape = mobile && landscapeProp;160 const transitionDuration = {161 enter: duration.enteringScreen,162 exit: duration.leavingScreen,163 };164 const hasMultipleChildren = children.length != null;165 const carousel = (166 <Carousel167 autoplay={open && autoplay && hasMultipleChildren}168 className={classes.carousel}169 containerStyle={{ height: "100%", ...containerStyle }}170 index={this.state.slideIndex}171 interval={interval}172 onChangeIndex={this.handleChange}173 slideClassName={classes.slide}174 >175 {React.Children.map(children, (c) =>176 React.cloneElement(c, {177 mobile,178 landscape,179 })180 )}181 </Carousel>182 );183 return (184 <div185 className={classNames(classes.root, {186 [classes.rootMobile]: mobile,187 })}188 open={open}189 onClose={onClose}190 // BackdropComponent={Backdrop}191 // BackdropProps={192 // ModalProps193 // ? { transitionDuration, ...ModalProps.BackdropProps }194 // : { transitionDuration }195 // }196 {...ModalProps}197 >198 <Fade appear in={open} timeout={transitionDuration}>199 <div200 className={classNames(classes.content, {201 [classes.contentMobile]: mobile,202 })}203 onClick={this.handleContentClick}204 >205 <Paper206 elevation={mobile ? 0 : 1}207 className={classes.carouselWrapper}208 >209 {carousel}210 </Paper>211 <div212 style={213 landscape214 ? {215 minWidth: 300,216 maxWidth: "calc(50% - 48px)",217 padding: 24,218 float: "right",219 }220 : null221 }222 >223 <div224 className={classNames(classes.footer, {225 [classes.footerMobile]: mobile,226 [classes.footerMobileLandscape]: landscape,227 })}228 >229 {label && (230 <Button231 variant="contained"232 color="secondary"233 onClick={onStart}234 {...ButtonProps}235 >236 Buy Now237 </Button>238 )}239 {hasMultipleChildren && (240 <Dots241 count={children.length}242 index={modulo(this.state.slideIndex, children.length)}243 className={classNames(classes.dots, {244 [classes.dotsMobile]: mobile,245 [classes.dotsMobileLandscape]: landscape,246 })}247 onDotClick={this.handleChange}248 />249 )}250 </div>251 </div>252 {!mobile && !hideArrows && hasMultipleChildren && (253 <div>254 <Fab255 className={classNames(classes.arrow, classes.arrowLeft)}256 onClick={() => this.decreaseIndex()}257 >258 <ArrowBackIcon className={classes.arrowIcon} />259 </Fab>260 <Fab261 className={classNames(classes.arrow, classes.arrowRight)}262 onClick={() => this.increaseIndex()}263 >264 <ArrowForwardIcon className={classes.arrowIcon} />265 </Fab>266 </div>267 )}268 </div>269 </Fade>270 </div>271 );272 }273}274AutoRotatingCarousel.defaultProps = {275 autoplay: true,276 interval: 3000,277 mobile: false,278 open: false,279 hideArrows: false,280};281AutoRotatingCarousel.propTypes = {282 /** If `false`, the auto play behavior is disabled. */283 autoplay: PropTypes.bool,284 /** Properties applied to the [Button](https://material-ui.com/api/button/) element. */285 ButtonProps: PropTypes.object,286 /** Object for customizing the CSS classes. */287 classes: PropTypes.object.isRequired,288 /** Override the inline-styles of the carousel container. */289 containerStyle: PropTypes.object,290 /** Delay between auto play transitions (in ms). */291 interval: PropTypes.number,292 /** Button text. If not supplied, the button will be hidden. */293 label: PropTypes.string,294 /** If `true`, slide will adjust content for wide mobile screens. */295 landscape: PropTypes.bool,296 /** If `true`, the screen width and height is filled. */297 mobile: PropTypes.bool,298 /** Properties applied to the [Modal](https://material-ui.com/api/modal/) element. */299 ModalProps: PropTypes.object,300 /** Fired when the index changed. Returns current index. */301 onChange: PropTypes.func,302 /** Fired when the gray background of the popup is pressed when it is open. */303 onClose: PropTypes.func,304 /** Fired when the user clicks the getting started button. */305 onStart: PropTypes.func,306 /** Controls whether the AutoRotatingCarousel is opened or not. */307 open: PropTypes.bool,308 /** If `true`, the left and right arrows are hidden in the desktop version. */309 hideArrows: PropTypes.bool,310};...
AutoRotatingCarousel.js
Source:AutoRotatingCarousel.js
1import React, { Component } from 'react'2import PropTypes from 'prop-types'3import Button from '@material-ui/core/Button'4import Paper from '@material-ui/core/Paper'5import { grey } from '@material-ui/core/colors'6import withStyles from '@material-ui/core/styles/withStyles'7import { duration } from '@material-ui/core/styles/transitions'8import Fab from '@material-ui/core/Fab'9import ArrowBackIcon from '@material-ui/icons/ArrowBack'10import ArrowForwardIcon from '@material-ui/icons/ArrowForward'11import Modal from '@material-ui/core/Modal'12import Fade from '@material-ui/core/Fade'13import Backdrop from '@material-ui/core/Backdrop'14import Dots from 'material-ui-dots'15import classNames from 'classnames'16import Carousel from './SwipableCarouselView'17import { modulo } from './util'18const styles = {19 root: {20 '& > *:focus': {21 outline: 'none'22 }23 },24 content: {25 width: '60%',26 maxWidth: 700,27 height: 'calc(100% - 96px)',28 maxHeight: 600,29 margin: '-16px auto 0',30 position: 'relative',31 top: '50%',32 transform: 'translateY(-50%)'33 },34 contentMobile: {35 width: '100%',36 height: '100%',37 maxWidth: 'initial',38 maxHeight: 'initial',39 margin: 0,40 top: 0,41 transform: 'none',42 '& > $carouselWrapper': {43 borderRadius: 044 }45 },46 arrow: {47 width: 48,48 height: 48,49 position: 'absolute',50 top: 'calc((100% - 96px) / 2 + 24px)'51 },52 arrowLeft: {53 left: -9654 },55 arrowRight: {56 right: -9657 },58 arrowIcon: {59 color: grey[700]60 },61 carouselWrapper: {62 overflow: 'hidden',63 borderRadius: 14,64 transform: 'scale(1.0)',65 background: 'transparent',66 height: '100%'67 },68 dots: {69 paddingTop: 36,70 margin: '0 auto'71 },72 dotsMobile: {73 paddingTop: 074 },75 dotsMobileLandscape: {76 paddingTop: 2077 },78 footer: {79 marginTop: -72,80 width: '100%',81 position: 'relative',82 textAlign: 'center'83 },84 footerMobile: {85 marginTop: -9286 },87 footerMobileLandscape: {88 marginTop: -3,89 transform: 'translateY(-50vh)',90 display: 'inline-block',91 width: 'auto'92 },93 slide: {94 width: '100%',95 height: '100%'96 },97 slideMobile: {98 width: '100%',99 height: '100%'100 },101 carousel: {102 height: '100%'103 },104 carouselContainer: {105 height: '100%'106 },107 closed: {}108}109class AutoRotatingCarousel extends Component {110 state = {111 slideIndex: 0112 }113 handleContentClick = (e) => e.stopPropagation() || e.preventDefault()114 handleChange = (slideIndex) => {115 this.setState({116 slideIndex117 }, this.onChange(slideIndex))118 }119 decreaseIndex () {120 const slideIndex = this.state.slideIndex - 1121 this.setState({122 slideIndex123 }, this.onChange(slideIndex))124 }125 increaseIndex () {126 const slideIndex = this.state.slideIndex + 1127 this.setState({128 slideIndex129 }, this.onChange(slideIndex))130 }131 onChange (slideIndex) {132 if (this.props.onChange) {133 this.props.onChange(modulo(slideIndex, this.props.children.length))134 }135 }136 render () {137 const {138 autoplay,139 ButtonProps,140 children,141 classes,142 containerStyle,143 hideArrows,144 interval,145 label,146 landscape: landscapeProp,147 mobile,148 ModalProps,149 open,150 onClose,151 onStart152 } = this.props153 const landscape = mobile && landscapeProp154 const transitionDuration = { enter: duration.enteringScreen, exit: duration.leavingScreen }155 const hasMultipleChildren = children.length != null156 const carousel = (157 <Carousel158 autoplay={open && autoplay && hasMultipleChildren}159 className={classes.carousel}160 containerStyle={{ height: '100%', ...containerStyle }}161 index={this.state.slideIndex}162 interval={interval}163 onChangeIndex={this.handleChange}164 slideClassName={classes.slide}165 >166 {167 React.Children.map(children, c => React.cloneElement(c, {168 mobile,169 landscape170 }))171 }172 </Carousel>173 )174 return (175 <Modal176 className={classNames(classes.root, {177 [classes.rootMobile]: mobile178 })}179 open={open}180 onClose={onClose}181 BackdropComponent={Backdrop}182 BackdropProps={ModalProps ? { transitionDuration, ...ModalProps.BackdropProps } : { transitionDuration }}183 {...ModalProps}184 >185 <Fade186 appear187 in={open}188 timeout={transitionDuration}189 >190 <div191 className={classNames(classes.content, {192 [classes.contentMobile]: mobile193 })}194 onClick={this.handleContentClick}195 >196 <Paper197 elevation={mobile ? 0 : 1}198 className={classes.carouselWrapper}>199 {carousel}200 </Paper>201 <div style={landscape ? { minWidth: 300, maxWidth: 'calc(50% - 48px)', padding: 24, float: 'right' } : null}>202 <div203 className={classNames(classes.footer, {204 [classes.footerMobile]: mobile,205 [classes.footerMobileLandscape]: landscape206 })}207 >208 {label && <Button209 variant='contained'210 onClick={onStart}211 {...ButtonProps}212 >213 {label}214 </Button>}215 {216 hasMultipleChildren &&217 <Dots218 count={children.length}219 index={modulo(this.state.slideIndex, children.length)}220 className={classNames(classes.dots, {221 [classes.dotsMobile]: mobile,222 [classes.dotsMobileLandscape]: landscape223 })}224 onDotClick={this.handleChange}225 />226 }227 </div>228 </div>229 {!mobile && !hideArrows && hasMultipleChildren && (230 <div>231 <Fab232 className={classNames(classes.arrow, classes.arrowLeft)}233 onClick={() => this.decreaseIndex()}234 >235 <ArrowBackIcon className={classes.arrowIcon} />236 </Fab>237 <Fab238 className={classNames(classes.arrow, classes.arrowRight)}239 onClick={() => this.increaseIndex()}240 >241 <ArrowForwardIcon className={classes.arrowIcon} />242 </Fab>243 </div>244 )}245 </div>246 </Fade>247 </Modal>248 )249 }250}251AutoRotatingCarousel.defaultProps = {252 autoplay: true,253 interval: 4000,254 mobile: true,255 open: false,256 hideArrows: false257}258AutoRotatingCarousel.propTypes = {259 /** If `false`, the auto play behavior is disabled. */260 autoplay: PropTypes.bool,261 /** Properties applied to the [Button](https://material-ui.com/api/button/) element. */262 ButtonProps: PropTypes.object,263 /** Object for customizing the CSS classes. */264 classes: PropTypes.object.isRequired,265 /** Override the inline-styles of the carousel container. */266 containerStyle: PropTypes.object,267 /** Delay between auto play transitions (in ms). */268 interval: PropTypes.number,269 /** Button text. If not supplied, the button will be hidden. */270 label: PropTypes.string,271 /** If `true`, slide will adjust content for wide mobile screens. */272 landscape: PropTypes.bool,273 /** If `true`, the screen width and height is filled. */274 mobile: PropTypes.bool,275 /** Properties applied to the [Modal](https://material-ui.com/api/modal/) element. */276 ModalProps: PropTypes.object,277 /** Fired when the index changed. Returns current index. */278 onChange: PropTypes.func,279 /** Fired when the gray background of the popup is pressed when it is open. */280 onClose: PropTypes.func,281 /** Fired when the user clicks the getting started button. */282 onStart: PropTypes.func,283 /** Controls whether the AutoRotatingCarousel is opened or not. */284 open: PropTypes.bool,285 /** If `true`, the left and right arrows are hidden in the desktop version. */286 hideArrows: PropTypes.bool287}...
Widget.jsx
Source:Widget.jsx
1import React from 'react'2import VizIndicatorType from '../VizIndicatorType'3import VizType from '../VizType'4export default ({ title, value, target, isComplete, vizType, vizIndicatorType }) => {5 let vizCssClassName = '';6 let centerChildren = false;7 let hasMultipleChildren = false;8 let vizIndicatorStyleProps = {};9 let vizIndicatorStylePropsLeft = {};10 let vizIndicatorStylePropsRight = {};11 switch(vizType)12 {13 case VizType.Blank:14 vizCssClassName = 'viz-blank';15 break;16 case VizType.Circle:17 vizCssClassName = 'viz-circle';18 break;19 case VizType.CirclePair:20 vizCssClassName = 'viz-circle-pair';21 break;22 case VizType.HalfCircle:23 vizCssClassName = 'viz-half-circle';24 break;25 case VizType.Square:26 vizCssClassName = 'viz-square';27 break;28 case VizType.SquareOutline:29 vizCssClassName = 'viz-square-outline';30 break;31 }32 let percentage = (isComplete || value >= target) ? 100 : (value/target) * 100;33 let cappedPercentage = 0;34 switch(vizIndicatorType)35 {36 case VizIndicatorType.RadialPositioned:37 const radius = 30;38 const buffer = 45;39 40 const angle = ((value % 60) / 60) * 360;41 const x = radius * Math.cos(angle) + buffer;42 const y = radius * Math.sin(angle) + buffer;43 vizIndicatorStyleProps = { left: y, top: x };44 break;45 case VizIndicatorType.Growing:46 centerChildren = true;47 vizIndicatorStyleProps = { height: `${percentage}%`, width: `${percentage}%` };48 break;49 case VizIndicatorType.Multiple:50 cappedPercentage = (100 / Math.sqrt(target));51 hasMultipleChildren = true;52 vizIndicatorStyleProps = { height: `${cappedPercentage}%`, width: `${cappedPercentage}%` };53 break;54 case VizIndicatorType.MergingPair:55 cappedPercentage = (percentage/100) * 80;56 vizIndicatorStylePropsLeft = { left: `${cappedPercentage}%`, top: `${cappedPercentage}%` };57 vizIndicatorStylePropsRight = { left: '80%', top: '80%' };58 break;59 case VizIndicatorType.Gauge:60 const degree = ((percentage/100) * 180) - 90;61 vizIndicatorStyleProps = { transform: `rotate(${degree}deg)` }62 break;63 case VizIndicatorType.EquilibriumPair:64 cappedPercentage = (percentage/100) * (40);65 vizIndicatorStylePropsLeft = { left: 0, top: 'inherit', bottom: `${cappedPercentage}%` };66 vizIndicatorStylePropsRight = { right: 0, top: `${cappedPercentage}%`, bottom: 'inherit' };67 break;68 }69 return <div className="widget">70 <h2>{title}</h2>71 <span className={'viz ' + vizCssClassName + (centerChildren ? ' viz-center-children' : '') + (hasMultipleChildren ? ' viz-multiple-children' : '') + (percentage >= 100 ? ' complete' : '')}>72 {value}73 {vizIndicatorType === VizIndicatorType.Multiple74 ? [...Array(Math.min(value, target))].map((e, i) => <span className="viz-indicator" key={i} style={vizIndicatorStyleProps}></span>)75 : (vizIndicatorType === VizIndicatorType.EquilibriumPair || vizIndicatorType == VizIndicatorType.MergingPair)76 ? <React.Fragment>77 <span className="viz-indicator viz-indicator-left" style={vizIndicatorStylePropsLeft}></span>78 <span className="viz-indicator viz-indicator-right" style={vizIndicatorStylePropsRight}></span>79 </React.Fragment>80 : (vizIndicatorType === VizIndicatorType.Cross)81 ? <React.Fragment>82 <span className="viz-indicator viz-indicator-cross viz-indicator-left"></span>83 <span className="viz-indicator viz-indicator-cross viz-indicator-right"></span>84 </React.Fragment>85 : <span className="viz-indicator" style={vizIndicatorStyleProps}></span>86 }87 </span>88 </div>...
main.js
Source:main.js
1import React from 'react'2import * as Emoji from './index'3import './default-svg.css'4export default function reactReplaceEmojis(reactElement, options) {5 // shortcut -> no children means nothing to replace6 if (!reactElement.props.children) return reactElement7 let newReactElement,8 hasMultipleChildren = Array.isArray(reactElement.props.children),9 newChildren = []10 // if element has multiple children call the recursive function once for each11 if (hasMultipleChildren) {12 for (let i in reactElement.props.children) {13 if (!reactElement.props.children.hasOwnProperty(i)) continue14 const child = reactElement.props.children[Number(i)];15 newChildren[i] = _applyCorrectReplace(child, options)16 }17 } else // if element has only one child call the recursive function directly18 newChildren = _applyCorrectReplace(reactElement.props.children, options)19 newReactElement = React.cloneElement(20 reactElement,21 {},22 newChildren23 );24 return newReactElement;25}26const _applyCorrectReplace = (child, options) =>27 React.isValidElement(child)28 ? reactReplaceEmojis(child, options)29 : replaceEmojis(child, options)30export function replaceEmojis(string, options) {31 if (!string) return;32 let array = [string]33 if (!options)34 options = {}35 options = {36 size: typeof options.size === 'string' ? options.size : undefined,37 outline: typeof options.outline === 'boolean' ? options.outline : undefined38 };39 /*40 * matches all emojis matches all attached components41 * \p{Extended_Pictographic}[\u{1f3fb}-\u{1f3ff}\u{1f9b0}-\u{1f9b3}]? un-matches "text style"42 * (\u200d\p{Extended_Pictographic}[\u{1f3fb}-\u{1f3ff}\u{1f9b0}-\u{1f9b3}]?)*[\u2640\u2642]?\ufe0f?(?!\ufe0e)/gu43 * matches all joined (ZWJ) emojis with all attached components matches attached gender44 */45 const regex = /\p{Extended_Pictographic}[\u{1f3fb}-\u{1f3ff}\u{1f9b0}-\u{1f9b3}]?\ufe0f?(\u200d\p{Extended_Pictographic}[\u{1f3fb}-\u{1f3ff}\u{1f9b0}-\u{1f9b3}]?\ufe0f?)*[\u2640\u2642]?\ufe0f?(?!\ufe0e)/gu;46 let m, j = 0;47 while ((m = regex.exec(string)) !== null) {48 // This is necessary to avoid infinite loops with zero-width matches49 if (m.index === regex.lastIndex) {50 regex.lastIndex++;51 }52 // find the code for the emoji53 let emojiName = 'U', done = false54 for (let i = 0; !done; i++) {55 let subUnicode = m[0].codePointAt(i)56 // dismiss low surrogates characters (56320-57343)57 if ((subUnicode >= 56320 && subUnicode <= 57343)) continue58 if (subUnicode)59 emojiName += '_' + subUnicode.toString(16).toUpperCase()60 // check if is done: if this hexcode is longer than 4, check the next but one codepoint61 done = m[0].codePointAt(i).toString(16).length > 462 ? !m[0].codePointAt(i + 2)63 : !m[0].codePointAt(i + 1)64 }65 let emojiSvg = Emoji[emojiName];66 options.key = j67 j++68 if (emojiSvg) {69 // gets last string ['String with {Emoji} and {Emoji} in it'] -> 'String with {Emoji} and {Emoji} in it'70 let workingString = array.pop()71 // 'String with {Emoji} and {Emoji} in it' -> ['String with ', ' and ', ' in it']72 workingString = workingString.split(m[0])73 // [] -> ['String with ']74 // ['String with ', ' and ', ' in it'] -> [' and ', ' in it']75 array.push(workingString.shift())76 // ['String with '] -> ['String with ', <Emoji>]77 array.push(React.createElement(emojiSvg, options))78 // [' and ', ' in it'] -> ' and {Emoji} in it'79 // ['String with ', <Emoji>] -> ['String with ', <Emoji>, ' and {Emoji} in it']80 array.push(workingString.join(m[0]))81 } else {82 console.warn('SVG not found: ' + emojiName);83 }84 }85 return array;86}...
form.js
Source:form.js
...12 this.state = {13 isSubmitting: false14 };15 this.childRefs = [];16 if (this.hasMultipleChildren()) {17 this.props.children.forEach(() => {18 this.childRefs.push(React.createRef());19 });20 } else {21 this.childRefs.push(React.createRef());22 }23 }24 submit() {25 this.props.onSubmit(this.handleSubmit());26 }27 onSubmit(e) {28 e.preventDefault();29 if (! this.state.isSubmitting) {30 this.setState({31 isSubmitting: true32 });33 this.submit();34 }35 }36 ready() {37 this.setState({38 isSubmitting: false39 });40 }41 handleSubmit() {42 let data = {};43 if (this.hasMultipleChildren()) {44 this.props.children.forEach((child, i) => {45 this.childRefs[i].current.handleSubmit(data);46 });47 return data;48 }49 this.childRefs[0].current.handleSubmit(data);50 return data;51 }52 hasMultipleChildren() {53 return this.props.children.length;54 }55 renderChildren() {56 if (this.hasMultipleChildren()) {57 return this.props.children.map((child, i) => {58 const TagName = child.type;59 return (60 <div key={i} className="form__input">61 <TagName ref={this.childRefs[i]} {...child.props} errors={this.props.errors} />62 </div>63 );64 });65 }66 const TagName = this.props.children.type;67 return (68 <div className="form__input">69 <TagName ref={this.childRefs[0]} {...this.props.children.props} />70 </div>...
index.js
Source:index.js
1const unified = require('unified')2const remarkParse = require('remark-parse')3const remarkRehype = require('remark-rehype')4const rehypeStringify = require('rehype-stringify')5/**6 * Transforms a string of inline markdown into a string of inline HTML7 *8 * @param {string} markdown - A string of markdown. Must only contain inline markdown elements. If block elements are detected, this function will throw an error.9 */10async function markdownToInlineHtml(markdown) {11 // Configure a unified processor12 var processor = unified()13 // Parse markdown to an [`mdast`](https://github.com/syntax-tree/mdast) syntax tree14 processor.use(remarkParse)15 // Throw an error if block elements are found16 processor.use(inlineElementsOnly)17 // Parse the [`mdast`](https://github.com/syntax-tree/mdast) syntax tree18 // into a [`hast`](https://github.com/syntax-tree/hast) syntax tree19 processor.use(remarkRehype)20 // Transform the [`hast`](https://github.com/syntax-tree/hast) syntax tree21 // into a string of HTML with rehype-stringify22 processor.use(rehypeStringify)23 // Use our configured processor to get from markdown to HTML24 const htmlOutput = String(await processor.process(markdown))25 return htmlOutput26}27function inlineElementsOnly() {28 return function transformer(tree) {29 // Ignore cases where we have an empty string (an empty tree)30 if (!tree.children || tree.children.length == 0) return31 // Throw an error if there are multiple child elements at the root32 const hasMultipleChildren = tree.children.length > 133 if (hasMultipleChildren)34 throw new Error('Please pass a markdown string without newlines.')35 // Throw an error if the single child element is anything other than a paragraph36 const hasNonParagraphChild = tree.children[0].type !== 'paragraph'37 if (hasNonParagraphChild)38 throw new Error(39 'Please pass inline markdown elements only. Headings and other block elements cannot be processed.'40 )41 // Flatten the children of the paragraph element onto the root of the tree42 // These children are guaranteed to be inline elements, because paragraphs43 // can only contain inline elements.44 const flatChildren = tree.children[0].children45 tree.children = flatChildren46 }47}...
RuleComponents.jsx
Source:RuleComponents.jsx
1import * as React from 'react';2export const RuleImageBlock = ({ images }) => (3 <div className='row RuleImageBlock'>4 {images.map(i => 5 <div key={i.path} className='col'>6 <img className='RuleImageBlock__image' src={i.path} />7 <p>{i.label}</p>8 </div>9 )}10 </div>11)12export const RuleNumber = ({ number, matchedNumber }) => (13 <span>14 <a className='RuleNumber__anchor' id={number}></a> 15 <a href={'#' + number} className={'RuleNumber' + (matchedNumber ? ' RuleNumber-match' : '')}>16 <span className='RuleNumber__decoration'>#</span>17 {number}18 </a>19 </span>20);21export const RuleSection = ({ number, title, children, matchedNumber, matchedHeading }) => ( 22 <div>23 <h4 className={'RuleSection__heading' + (matchedHeading ? ' RuleSection__heading-match' : '')}>24 {number && <RuleNumber number={number} matchedNumber={matchedNumber} />}25 {title}26 </h4>27 {children}28 </div>29);30export const RuleText = ({ subheading, number, children, matchedNumber, matchedHeading }) => {31 var numberDisplay = 'none';32 if (number && subheading) {33 numberDisplay = 'header';34 } else if (number) {35 numberDisplay = 'inline';36 }37 const hasMultipleChildren = React.Children.count(children) > 1;38 return (39 <div>40 {subheading &&41 <h5 className={'RuleText__subheading' + (matchedHeading ? ' RuleText__subheading-match' : '')}>42 {numberDisplay == 'header' && <RuleNumber number={number} matchedNumber={matchedNumber} />}43 {subheading}44 </h5>}45 <div className='RuleText'>46 {React.Children.map(children, child => (47 (typeof (child) == 'string')48 ? <p className={'RuleText__text' + (hasMultipleChildren ? ' RuleText__text-lead' : '')}>49 {numberDisplay == 'inline' && <RuleNumber number={number} matchedNumber={matchedNumber} />} {child}50 </p>51 : child52 ))}53 </div>54 </div>55 );...
Carousel.js
Source:Carousel.js
1import React, { useEffect, useState } from "react";2import styles from "./Carousel.styles";3import { styled } from "../styled";4import classNames from "classnames";5import LeftArrow from "../icons/left-arrow-icon/LeftArrow";6import RightArrow from "../icons/right-arrow-icon/RightArrow";7function Carousel({ className, children, selectedSlide = 0 }) {8 const [selected, setSelected] = useState(selectedSlide);9 const [slides, setSlides] = useState([]);10 const [dots, setDots] = useState([]);11 const hasMultipleChildren = children.length > 1;12 const previous = () =>13 setSelected(selected === 0 ? children.length - 1 : selected - 1);14 const next = () =>15 setSelected(selected === children.length - 1 ? 0 : selected + 1);16 useEffect(() => setSelected(selectedSlide), [selectedSlide]);17 useEffect(() => {18 setSlides(19 children.map((child, index) => (20 <section21 className="carousel-section"22 key={"carousel-section-" + index}23 style={{24 transform: `translate(calc(100% * ${index - selected}))`,25 }}26 >27 {child}28 </section>29 ))30 );31 }, [selected, children]);32 useEffect(33 () =>34 setDots(35 children.map((_, index) => (36 <svg37 key={"dot-" + index}38 className={classNames(["dot", { active: index === selected }])}39 >40 <circle cx="6" cy="6" r="3" />41 </svg>42 ))43 ),44 [selected, children]45 );46 return (47 <div className={className}>48 {hasMultipleChildren && (49 <span className="left-arrow" onClick={previous}>50 <LeftArrow />51 </span>52 )}53 {slides}54 {hasMultipleChildren && (55 <span className="right-arrow" onClick={next}>56 <RightArrow />57 </span>58 )}59 {hasMultipleChildren && <div className="dots">{dots}</div>}60 </div>61 );62}...
Using AI Code Generation
1const { hasMultipleChildren } = require('playwright/lib/server/dom.js');2const { chromium } = require('playwright');3(async () => {4 const browser = await chromium.launch();5 const context = await browser.newContext();6 const page = await context.newPage();7 const element = await page.$('div#orb-modules');8 console.log(await hasMultipleChildren(element));9 await browser.close();10})();11const { childCount } = require('playwright/lib/server/dom.js');12const { chromium } = require('playwright');13(async () => {14 const browser = await chromium.launch();15 const context = await browser.newContext();16 const page = await context.newPage();17 const element = await page.$('div#orb-modules');18 console.log(await childCount(element));19 await browser.close();20})();21const { childCount } = require('playwright/lib/server/dom.js');22const { chromium } = require('playwright');23(async () => {24 const browser = await chromium.launch();25 const context = await browser.newContext();26 const page = await context.newPage();27 const element = await page.$('div#orb-modules');28 console.log(await childCount(element));29 await browser.close();30})();31const { childCount } = require('playwright/lib/server/dom.js');32const { chromium } = require('playwright');33(async () => {34 const browser = await chromium.launch();35 const context = await browser.newContext();36 const page = await context.newPage();37 const element = await page.$('div#
Using AI Code Generation
1const { hasMultipleChildren } = require('playwright/lib/server/dom.js');2const { chromium } = require('playwright');3(async () => {4 const browser = await chromium.launch();5 const page = await browser.newPage();6 await page.type('input[name="q"]', 'playwright');7 const searchBox = await page.$('input[name="q"]');8 const searchButton = await page.$('input[name="btnK"]');9 const hasMultipleChildren = await hasMultipleChildren(searchBox);10 const hasMultipleChildren = await hasMultipleChildren(searchButton);11 await browser.close();12})();13const { hasPointerCapture } = require('playwright/lib/server/dom.js');14const { chromium } = require('playwright');15(async () => {16 const browser = await chromium.launch();17 const page = await browser.newPage();18 await page.type('input[name="q"]', 'playwright');19 const searchBox = await page.$('input[name="q"]');20 const hasPointerCapture = await hasPointerCapture(searchBox);21 await browser.close();22})();23const { hasScrollEvent } = require('playwright/lib/server/dom.js');24const { chromium } = require('playwright');25(async () => {26 const browser = await chromium.launch();
Using AI Code Generation
1const { hasMultipleChildren } = require('playwright/lib/server/dom.js');2const { chromium } = require('playwright');3(async () => {4 const browser = await chromium.launch();5 const page = await browser.newPage();6 await page.type('input[name="q"]', 'playwright');7 const searchBox = await page.$('input[name="q"]');8 const searchButton = await page.$('input[name="btnK"]');9 const hasMultipleChildren = await hasMultipleChildren(searchBox);10 const hasMultipleChildren = await hasMultipleChildren(searchButton);11 await browser.close();12})();13const { hasPointerCapture } = require('playwright/lib/server/dom.js');14const { chromium } = require('playwright');15(async () => {16 const browser = await chromium.launch();17 const page = await browser.newPage();18 await page.type('input[name="q"]', 'playwright');
Using AI Code Generation
1const { hasMultipleChildren } = require('playwright/lib/server/dom.js');2const {chromium} = require('playwright');3(async () => {4 const browser = await chromium.launch();5 const context = await browser.newContext();6 const page = await context.newPage();7 const element = await page.$('a');8 const hasMultipleChildren = await page.evaluate(element => hasMultipleChildren(element), element);9 console.log(hasMultipleChildren);10 await browser.close();11})();12### hasMultipleChildren(elementHandle)
Using AI Code Generation
1const { hasMultipleChildren } = require('playwright/lib/server/dom.js');2const { chromium } = require('playwright');3(async () => {4 const browser = await chromium.launch({5 });6 const context = await browser.newContext();7 const page = await context.newPage();8 const element = await page.$('body');9 const hasChildren = await hasMultipleChildren(element);10 await browser.close();11})();12### hasMultipleChildren(element)
Using AI Code Generation
1const { hasMultipleChildren } = require('@playwright/test/lib/server/frames');2const { test, expect } = require('@playwright/test');3test('test', async ({ page }) => {4 expect(await hasMultipleChildren(page, '.navbar__inner')).toBe(true);5});6- [hasMultipleChildren](#hasmultiplechildren)7 - [Parameters](#parameters)8 - [Examples](#examples)9- [hasTextContent](#hastextcontent)10 - [Parameters](#parameters-1)11 - [Examples](#examples-1)12- [hasTextContent](#hastextcontent-1)13 - [Parameters](#parameters-2)14 - [Examples](#examples-2)15- [hasTextContent](#hastextcontent-2)16 - [Parameters](#parameters-3)17 - [Examples](#examples-3)18- [hasTextContent](#hastextcontent-3)19 - [Parameters](#parameters-4)20 - [Examples](#examples-4)21- [hasTextContent](#hastextcontent-4)22 - [Parameters](#parameters-5)23 - [Examples](#examples-5)24- [hasTextContent](#hastextcontent-5)25 - [Parameters](#parameters-6)26 - [Examples](#examples-6)27- [hasTextContent](#hastextcontent-6)28 - [Parameters](#parameters-7)29 - [Examples](#examples-7)30- [hasTextContent](#hastextcontent-7)31 - [Parameters](#parameters-8)32 - [Examples](#examples-8)33- [hasTextContent](#hastextcontent-8)34 - [Parameters](#parameters-9)35 - [Examples](#examples-9)36- [hasTextContent](#hastextcontent-9)37 - [Parameters](#parameters-10)38 - [Examples](#examples-10)
Using AI Code Generation
1const { hasMultipleChildren } = require('playwright/lib/server/dom.js');2const { chromium } = require('playwright');3(async () => {4 const browser = await chromium.launch({5 });6 const context = await browser.newContext();7 const page = await context.newPage();8 const element = await page.$('body');9 const hasChildren = await hasMultipleChildren(element);10 await browser.close();11})();12### hasMultipleChildren(element)13 const searchBox = await page.$('input[name="q"]');14 const hasPointerCapture = await hasPointerCapture(searchBox);15 await browser.close();16})();17const { hasScrollEvent } = require('playwright/lib/server/dom.js');18const { chromium } = require('playwright');19(async () => {20 const browser = await chromium.launch();
Using AI Code Generation
1(async () => {2 const { chromium } = require('playwright');3 const browser = await chromium.launch();4 const page = await browser.newPage();5 await page.waitForSelector('text=Get started');6 const element = await page.$('text=Get started');7 const hasMultipleChildren = await element._hasMultipleChildren();8 console.log('Has multiple children: ' + hasMultipleChildren);9 await browser.close();10})();11#### elementHandle._hasMultipleChildren()
Using AI Code Generation
1const { hasMultipleChildren } = require('playwright/lib/client/selectorEngine');2const { chromium } = require('playwright');3(async () => {4 const browser = await chromium.launch();5 const context = await browser.newContext();6 const page = await context.newPage();7 const element = await page.$('html');8 const result = await hasMultipleChildren(element);9 console.log(result);10 await browser.close();11})();12We welcome all contributions! Please read our [contributing guide](
Using AI Code Generation
1const { hasMultipleChildren } = require('playwright/lib/server/dom.js');2const {chromium} = require('playwright');3(async () => {4 const browser = await chromium.launch();5 const context = await browser.newContext();6 const page = await context.newPage();7 const element = await page.$('a');8 const hasMultipleChildren = await page.evaluate(element => hasMultipleChildren(element), element);9 console.log(hasMultipleChildren);10 await browser.close();11})();12### hasMultipleChildren(elementHandle)13[Apache 2.0](LICENSE)
Using AI Code Generation
1const { hasMultipleChildren } = require('playwright/lib/server/dom.js');2const { parse } = require('playwright/lib/server/parseSelector.js');3const { Page } = require('playwright/lib/server/page.js');4const { ElementHandle } = require('playwright/lib/server/dom.js');5const { JSHandle } = require('playwright/lib/server/jsHandle.js');6const selector = 'div > div > span';7const parsedSelector = parse(selector);8const page = new Page(null, null, null, null);9const elementHandle = new ElementHandle(page, null, null, null, null);10const jsHandle = new JSHandle(elementHandle, null, null);11const result = hasMultipleChildren(jsHandle, parsedSelector);12console.log(result);13How to Use Playwright to Automate Browser Testing (Part 2)14How to Use Playwright to Automate Browser Testing (Part 3)15How to Use Playwright to Automate Browser Testing (Part 4)16How to Use Playwright to Automate Browser Testing (Part 5)17How to Use Playwright to Automate Browser Testing (Part 6)18How to Use Playwright to Automate Browser Testing (Part 7)19How to Use Playwright to Automate Browser Testing (Part 8)20How to Use Playwright to Automate Browser Testing (Part 9)21How to Use Playwright to Automate Browser Testing (Part 10)22How to Use Playwright to Automate Browser Testing (Part 11)
LambdaTest’s Playwright tutorial will give you a broader idea about the Playwright automation framework, its unique features, and use cases with examples to exceed your understanding of Playwright testing. This tutorial will give A to Z guidance, from installing the Playwright framework to some best practices and advanced concepts.
Get 100 minutes of automation test minutes FREE!!