guestbell-forms 3.0.2 → 3.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/components/base/input/BaseInput.d.ts +1 -1
- package/build/components/base/input/BaseInput.js.map +1 -1
- package/build/components/button/Button.d.ts +3 -1
- package/build/components/button/Button.js +9 -8
- package/build/components/button/Button.js.map +1 -1
- package/build/components/checkbox/Checkbox.js +3 -3
- package/build/components/checkbox/Checkbox.js.map +1 -1
- package/build/components/dynamicSubmit/DynamicSubmit.js +5 -3
- package/build/components/dynamicSubmit/DynamicSubmit.js.map +1 -1
- package/build/components/form/FormValidationSummary.js +5 -5
- package/build/components/form/FormValidationSummary.js.map +1 -1
- package/build/components/inputHeader/InputHeader.d.ts +1 -1
- package/build/components/inputHeader/InputHeader.js +4 -4
- package/build/components/inputHeader/InputHeader.js.map +1 -1
- package/build/components/numberInput/NumberInput.js +4 -4
- package/build/components/numberInput/NumberInput.js.map +1 -1
- package/build/components/openingHours/openingHoursDay/OpeningHoursDay.js +4 -4
- package/build/components/openingHours/openingHoursDay/OpeningHoursDay.js.map +1 -1
- package/build/components/submit/Submit.d.ts +1 -0
- package/build/components/text/Text.js +3 -3
- package/build/components/text/Text.js.map +1 -1
- package/build/components/timeSpan/TimeSpan.js +4 -4
- package/build/components/timeSpan/TimeSpan.js.map +1 -1
- package/build/dist/report.html +1 -1
- package/package.json +1 -1
@@ -1,5 +1,5 @@
|
|
1
1
|
import * as React from 'react';
|
2
|
-
import { TippyProps } from '@tippy.js/react';
|
2
|
+
import type { TippyProps } from '@tippy.js/react';
|
3
3
|
import * as Validators from '../../../validators';
|
4
4
|
import { FormContextProps } from '../../form/FormContext';
|
5
5
|
import { Theme } from '../../../types/Theme';
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"BaseInput.js","names":["defaultBaseTranslations","required","BaseInput","React","Component","constructor","props","subscribe","guid","res","handleValueChange","value","state","isValid","errors","touched","defaultTouched","disabled","focused","handleValueChangeEnabled","containerRef","createRef","inputRef","handleChange","bind","handleBlur","handleFocus","setValid","focus","scrollTo","setInvalid","disableComponent","enableComponent","touch","unTouch","subscribeSelf","componentWillUnmount","ignoreContext","formContext","unSubscribe","componentId","componentDidUpdate","oldProps","oldState","validators","customValidators","domNode","ReactDOM","findDOMNode","current","scrollIntoView","behavior","setState","shouldComponentUpdate","nextProps","nextState","shouldUpdate","shallowEqual","reRendersWhenContextChanges","undefined","getValidationClass","extraErrors","showValidation","length","renderDefaultValidation","finalErrors","concat","filter","i","lastValidation","map","item","index","event","target","onTheFlightValidate","onChange","componentApi","validation","name","validationName","title","label","e","onBlur","touchOn","Object","assign","onFocus","getDisabled","updateCallback","renderLabel","touchable","tooltip","classNames","renderTooltip","renderTitle","initializing","translations","getTranslations","push","forEach","validator","validInner","Validators","EmailValidator","Validate","error","NumberValidator","LatitudeValidator","LongitudeValidator","UrlValidator","Error","customValidator","onErrorsChanged","content","Tippy","require","default","document","body","tooltipProps","_defaultTranslations","className"],"sources":["../../../../src/lib/components/base/input/BaseInput.tsx"],"sourcesContent":["// Libs\r\nimport * as React from 'react';\r\nimport * as ReactDOM from 'react-dom';\r\nimport { TippyProps } from '@tippy.js/react';\r\n\r\n// Misc\r\nimport * as Validators from '../../../validators';\r\nimport guid from '../../utils/Guid';\r\nimport { FormContextProps } from '../../form/FormContext';\r\nimport { shallowEqual } from '../../utils/ShallowEqual';\r\nimport { Theme } from '../../../types/Theme';\r\nimport classNames from 'classnames';\r\n\r\nexport interface ComponentApi {\r\n focus: () => void;\r\n touch: () => void;\r\n unTouch: () => void;\r\n enableComponent: () => void;\r\n disableComponent: () => void;\r\n scrollTo: () => void;\r\n}\r\n\r\nexport type ValidationError = string | JSX.Element;\r\n\r\nexport type AllowedHtmlElements =\r\n | HTMLInputElement\r\n | HTMLSelectElement\r\n | HTMLTextAreaElement;\r\n\r\nexport const defaultBaseTranslations = {\r\n required: 'Required',\r\n};\r\n\r\nexport type BaseTranslations = Partial<typeof defaultBaseTranslations>;\r\n\r\nexport type BaseInputProps<\r\n HTMLType extends AllowedHtmlElements,\r\n TranslationsT extends BaseTranslations = BaseTranslations\r\n> = {\r\n theme?: Theme;\r\n id?: string;\r\n disabled?: boolean;\r\n className?: string;\r\n label?: string | JSX.Element;\r\n tooltip?: string | JSX.Element;\r\n tooltipProps?: TippyProps;\r\n value?: string;\r\n onChange?: (e: React.ChangeEvent<HTMLType>, isValid: boolean) => void;\r\n required?: boolean;\r\n customValidators?: Validators.IBaseValidator[];\r\n validators?: Validators.ValidatorTypes[];\r\n noValidate?: boolean;\r\n validationName?: string;\r\n touchOn?: 'focus' | 'blur';\r\n ignoreContext?: boolean;\r\n onTheFlightValidate?: (value: string) => boolean;\r\n onFocus?: (e: React.SyntheticEvent<{}>) => void;\r\n onBlur?: () => void;\r\n onSuggestionsClosed?: () => void;\r\n onSuggestionsOpened?: () => void;\r\n onClick?: (e: React.MouseEvent) => void;\r\n title?: string | JSX.Element;\r\n onKeyDown?: (e: React.KeyboardEvent<HTMLElement>) => void;\r\n errors?: ValidationError[];\r\n onErrorsChanged?: (errors: ValidationError[]) => void;\r\n showValidation?: boolean;\r\n reRendersWhenContextChanges?: boolean;\r\n defaultTouched?: boolean;\r\n translations?: TranslationsT;\r\n inputGroupClassName?: string;\r\n} & FormContextProps;\r\n\r\nexport interface BaseInputState {\r\n isValid: boolean;\r\n value: string;\r\n errors: ValidationError[];\r\n validator: undefined;\r\n touched: boolean;\r\n disabled: boolean;\r\n focused: boolean;\r\n handleValueChangeEnabled: boolean;\r\n}\r\n\r\nexport class BaseInput<\r\n P extends BaseInputProps<HTMLType, TranslationsT>,\r\n S extends BaseInputState,\r\n HTMLType extends AllowedHtmlElements,\r\n TranslationsT extends BaseTranslations = BaseTranslations\r\n> extends React.Component<P, S> implements ComponentApi {\r\n public static defaultProps: BaseInputProps<never> = {\r\n className: undefined,\r\n required: false,\r\n label: undefined,\r\n disabled: false,\r\n touchOn: 'focus',\r\n ignoreContext: false,\r\n showValidation: true,\r\n formContext: undefined,\r\n reRendersWhenContextChanges: false,\r\n };\r\n\r\n public componentId = guid();\r\n\r\n public inputRef: React.RefObject<HTMLType>;\r\n\r\n protected containerRef: React.RefObject<HTMLDivElement>;\r\n\r\n private lastValidation: JSX.Element[];\r\n\r\n constructor(props: P, subscribe: boolean = true) {\r\n super(props);\r\n const res = this.handleValueChange(this.props.value, true, [], props, true);\r\n this.state = {\r\n isValid: res.isValid,\r\n errors: res.errors,\r\n value: props.value ? props.value : '',\r\n touched: props.defaultTouched,\r\n disabled: false,\r\n focused: false,\r\n handleValueChangeEnabled: true,\r\n } as S;\r\n this.containerRef = React.createRef<HTMLDivElement>();\r\n this.inputRef = React.createRef<HTMLType>();\r\n this.handleChange = this.handleChange.bind(this);\r\n this.handleBlur = this.handleBlur.bind(this);\r\n this.handleFocus = this.handleFocus.bind(this);\r\n this.setValid = this.setValid.bind(this);\r\n this.focus = this.focus.bind(this);\r\n this.scrollTo = this.scrollTo.bind(this);\r\n this.setInvalid = this.setInvalid.bind(this);\r\n this.disableComponent = this.disableComponent.bind(this);\r\n this.enableComponent = this.enableComponent.bind(this);\r\n this.touch = this.touch.bind(this);\r\n this.unTouch = this.unTouch.bind(this);\r\n if (subscribe) {\r\n this.subscribeSelf(props);\r\n }\r\n }\r\n\r\n public componentWillUnmount() {\r\n if (!this.props.ignoreContext) {\r\n this.props.formContext &&\r\n this.props.formContext.unSubscribe(this.componentId);\r\n }\r\n }\r\n\r\n public componentDidUpdate(oldProps: P, oldState: S) {\r\n if (\r\n oldProps.value !== this.props.value ||\r\n oldProps.validators !== this.props.validators ||\r\n oldProps.customValidators !== this.props.customValidators ||\r\n oldProps.required !== this.props.required\r\n ) {\r\n this.handleValueChange(this.props.value, true, [], this.props);\r\n }\r\n }\r\n\r\n public scrollTo() {\r\n const domNode: HTMLDivElement = ReactDOM.findDOMNode(\r\n (this.containerRef as React.RefObject<HTMLDivElement>).current\r\n ) as HTMLDivElement;\r\n domNode && domNode.scrollIntoView({ behavior: 'smooth' });\r\n }\r\n\r\n public touch() {\r\n this.setState({ touched: true });\r\n this.handleValueChange(this.state.value || '');\r\n }\r\n\r\n public unTouch() {\r\n this.setState({ touched: false });\r\n }\r\n\r\n public disableComponent() {\r\n this.setState({ disabled: true });\r\n }\r\n\r\n public enableComponent() {\r\n this.setState({ disabled: false });\r\n }\r\n\r\n public focus() {\r\n if (this.inputRef) {\r\n const domNode: HTMLElement = ReactDOM.findDOMNode(\r\n (this.inputRef as React.RefObject<HTMLElement>).current\r\n ) as HTMLElement;\r\n domNode && domNode.focus();\r\n }\r\n this.touch();\r\n }\r\n\r\n public shouldComponentUpdate(nextProps: P, nextState: S) {\r\n let shouldUpdate =\r\n !shallowEqual(\r\n this.props,\r\n nextProps,\r\n !this.props.reRendersWhenContextChanges ? 'formContext' : undefined\r\n ) || !shallowEqual(this.state, nextState);\r\n return shouldUpdate;\r\n }\r\n\r\n protected getValidationClass(extraErrors?: ValidationError[]) {\r\n if (!this.props.showValidation || !this.state.touched) {\r\n return 'validation__success';\r\n }\r\n return this.state.isValid &&\r\n (!this.props.errors || this.props.errors.length === 0) &&\r\n (!this.state.errors || this.state.errors.length === 0) &&\r\n (!extraErrors || extraErrors.length === 0)\r\n ? 'validation__success'\r\n : 'validation__error';\r\n }\r\n\r\n protected renderDefaultValidation(extraErrors?: ValidationError[]) {\r\n if (this.props.disabled) {\r\n return null;\r\n }\r\n if (!this.props.showValidation) {\r\n return null;\r\n }\r\n let finalErrors: ValidationError[] = this.state.errors;\r\n if (!finalErrors) {\r\n finalErrors = [];\r\n }\r\n if (extraErrors) {\r\n finalErrors = finalErrors.concat(extraErrors);\r\n }\r\n if (this.props.errors) {\r\n finalErrors = finalErrors.concat(this.props.errors);\r\n }\r\n finalErrors = finalErrors.filter(i => i);\r\n if (finalErrors.length > 0) {\r\n this.lastValidation = finalErrors.map((item, index) => (\r\n <li key={index} className=\"validation__item\">\r\n {item}\r\n </li>\r\n ));\r\n }\r\n return (\r\n <div className=\"validation__container\">\r\n <ul className=\"validation__ul\">{this.lastValidation}</ul>\r\n </div>\r\n );\r\n }\r\n\r\n protected handleChange(\r\n event: React.ChangeEvent<HTMLType>,\r\n isValid?: boolean,\r\n errors: ValidationError[] = []\r\n ) {\r\n let value = event.target.value;\r\n if (\r\n !this.props.onTheFlightValidate ||\r\n (this.props.onTheFlightValidate && this.props.onTheFlightValidate(value))\r\n ) {\r\n const res = this.handleValueChange(value, isValid, errors);\r\n if (this.props.onChange) {\r\n this.props.onChange(event, res.isValid);\r\n }\r\n }\r\n }\r\n\r\n protected subscribeSelf(props: P) {\r\n if (!props.ignoreContext && props.formContext) {\r\n props.formContext.subscribe(this.componentId, {\r\n componentApi: {\r\n disableComponent: this.disableComponent,\r\n enableComponent: this.enableComponent,\r\n touch: this.touch,\r\n unTouch: this.unTouch,\r\n scrollTo: this.scrollTo,\r\n focus: this.focus,\r\n },\r\n validation: {\r\n isValid: this.state.isValid,\r\n errors: this.state.errors,\r\n name: this.props.validationName\r\n ? this.props.validationName\r\n : this.props.title\r\n ? this.props.title\r\n : this.props.label,\r\n },\r\n });\r\n }\r\n }\r\n\r\n protected handleBlur(e: React.FocusEvent<HTMLType>) {\r\n this.props.onBlur && this.props.onBlur();\r\n let state = { focused: false };\r\n if (!this.state.touched && this.props.touchOn === 'blur') {\r\n state = Object.assign(state, { touched: true });\r\n this.handleValueChange(this.state.value);\r\n }\r\n this.setState(state);\r\n }\r\n\r\n protected handleFocus(e: React.FocusEvent<HTMLType>) {\r\n if (!this.props.disabled) {\r\n this.props.onFocus && this.props.onFocus(e);\r\n let state = { focused: true };\r\n if (!this.state.touched && this.props.touchOn === 'focus') {\r\n state = Object.assign(state, { touched: true });\r\n this.handleValueChange(this.state.value);\r\n }\r\n this.setState(state);\r\n }\r\n }\r\n\r\n protected getDisabled() {\r\n return this.state.disabled ? this.state.disabled : this.props.disabled;\r\n }\r\n\r\n protected setValid() {\r\n this.setState(\r\n () => ({ isValid: true, errors: [] }),\r\n () => {\r\n if (!this.props.ignoreContext) {\r\n this.props.formContext &&\r\n this.props.formContext.updateCallback(this.componentId, {\r\n validation: {\r\n isValid: true,\r\n errors: [],\r\n },\r\n });\r\n }\r\n }\r\n );\r\n }\r\n\r\n protected setInvalid(errors: ValidationError[] = []) {\r\n this.setState(\r\n () => ({ isValid: false, errors }),\r\n () => {\r\n if (!this.props.ignoreContext) {\r\n this.props.formContext &&\r\n this.props.formContext.updateCallback(this.componentId, {\r\n validation: {\r\n isValid: false,\r\n errors: errors,\r\n },\r\n });\r\n }\r\n }\r\n );\r\n }\r\n\r\n protected renderLabel(touchable: boolean = false) {\r\n if (!this.props.tooltip || (this.props.tooltip && this.props.title)) {\r\n return (\r\n <span\r\n className={classNames('w-100', { 'label--no-touch': !touchable })}\r\n >\r\n {this.props.label}\r\n </span>\r\n );\r\n }\r\n return (\r\n <React.Fragment>\r\n <span className={touchable ? '' : 'label--no-touch'}>\r\n {this.props.label}\r\n </span>\r\n {this.renderTooltip()}\r\n </React.Fragment>\r\n );\r\n }\r\n\r\n protected renderTitle() {\r\n if (!this.props.tooltip) {\r\n return this.props.title;\r\n }\r\n return (\r\n <React.Fragment>\r\n {this.props.title}\r\n {this.renderTooltip()}\r\n </React.Fragment>\r\n );\r\n }\r\n\r\n protected handleValueChange(\r\n value: string,\r\n isValid: boolean = true,\r\n errors: ValidationError[] = [],\r\n props: P = this.props,\r\n initializing: boolean = false\r\n ): {\r\n isValid: boolean;\r\n errors: ValidationError[];\r\n } {\r\n if (!initializing && !this.state.handleValueChangeEnabled) {\r\n return { isValid, errors: [] };\r\n }\r\n if (props.required && !value) {\r\n const translations = this.getTranslations(defaultBaseTranslations);\r\n errors.push(translations.required);\r\n isValid = false;\r\n } else {\r\n if (!props.required && !value) {\r\n isValid = true;\r\n } else {\r\n if (props.validators) {\r\n isValid = true;\r\n props.validators.forEach(validator => {\r\n let validInner = false;\r\n switch (validator) {\r\n case 'email':\r\n validInner = new Validators.EmailValidator().Validate(\r\n value,\r\n props.required,\r\n error => errors.push(error)\r\n );\r\n break;\r\n case 'number':\r\n validInner = new Validators.NumberValidator().Validate(\r\n value,\r\n props.required,\r\n error => errors.push(error)\r\n );\r\n break;\r\n case 'latitude':\r\n validInner = new Validators.LatitudeValidator().Validate(\r\n value,\r\n props.required,\r\n error => errors.push(error)\r\n );\r\n break;\r\n case 'longitude':\r\n validInner = new Validators.LongitudeValidator().Validate(\r\n value,\r\n props.required,\r\n error => errors.push(error)\r\n );\r\n break;\r\n case 'url':\r\n validInner = new Validators.UrlValidator().Validate(\r\n value,\r\n props.required,\r\n error => errors.push(error)\r\n );\r\n break;\r\n default:\r\n throw new Error(`Validator ${validator} not implemented`);\r\n }\r\n if (isValid && !validInner) {\r\n isValid = validInner;\r\n }\r\n });\r\n }\r\n if (props.customValidators) {\r\n props.customValidators.forEach(customValidator => {\r\n let validInner = false;\r\n validInner = customValidator.Validate(\r\n value,\r\n props.required,\r\n error => errors.push(error)\r\n );\r\n if (isValid && !validInner) {\r\n isValid = validInner;\r\n }\r\n });\r\n }\r\n }\r\n }\r\n props.onErrorsChanged && props.onErrorsChanged(errors);\r\n if (!initializing) {\r\n this.setState({ value, isValid, errors });\r\n if (!props.ignoreContext) {\r\n props.formContext &&\r\n props.formContext.updateCallback(this.componentId, {\r\n validation: {\r\n isValid: isValid,\r\n errors: errors,\r\n },\r\n });\r\n }\r\n }\r\n return { isValid, errors };\r\n }\r\n\r\n protected renderTooltip(\r\n content: JSX.Element = <span className=\"label--help-icon\">?</span>\r\n ) {\r\n if (this.props.tooltip) {\r\n const Tippy = require('@tippy.js/react').default;\r\n return (\r\n <Tippy\r\n content={this.props.tooltip}\r\n placement=\"bottom\"\r\n animation=\"scale-subtle\"\r\n arrow={false}\r\n duration={200}\r\n delay={[75, 0]}\r\n distance={8}\r\n interactive={true}\r\n appendTo={document?.body}\r\n trigger=\"mouseenter focus\"\r\n {...this.props.tooltipProps}\r\n >\r\n {content}\r\n </Tippy>\r\n );\r\n }\r\n return content;\r\n }\r\n\r\n protected getTranslations(\r\n _defaultTranslations: BaseTranslations\r\n ): TranslationsT {\r\n return {\r\n ..._defaultTranslations,\r\n ...this.props.translations,\r\n };\r\n }\r\n}\r\nexport default BaseInput;\r\n"],"mappings":";;;;;;;AACA;;AACA;;AAIA;;AACA;;AAEA;;AAEA;;;;;;;;;;;;;;;;AAkBO,MAAMA,uBAAuB,GAAG;EACrCC,QAAQ,EAAE;AAD2B,CAAhC;;;AAsDA,MAAMC,SAAN,SAKGC,KAAK,CAACC,SALT,CAKiD;EAqBtDC,WAAW,CAACC,KAAD,EAAsC;IAAA,IAA3BC,SAA2B,uEAAN,IAAM;IAC/C,MAAMD,KAAN;;IAD+C,qCAR5B,IAAAE,aAAA,GAQ4B;;IAAA;;IAAA;;IAAA;;IAE/C,MAAMC,GAAG,GAAG,KAAKC,iBAAL,CAAuB,KAAKJ,KAAL,CAAWK,KAAlC,EAAyC,IAAzC,EAA+C,EAA/C,EAAmDL,KAAnD,EAA0D,IAA1D,CAAZ;IACA,KAAKM,KAAL,GAAa;MACXC,OAAO,EAAEJ,GAAG,CAACI,OADF;MAEXC,MAAM,EAAEL,GAAG,CAACK,MAFD;MAGXH,KAAK,EAAEL,KAAK,CAACK,KAAN,GAAcL,KAAK,CAACK,KAApB,GAA4B,EAHxB;MAIXI,OAAO,EAAET,KAAK,CAACU,cAJJ;MAKXC,QAAQ,EAAE,KALC;MAMXC,OAAO,EAAE,KANE;MAOXC,wBAAwB,EAAE;IAPf,CAAb;IASA,KAAKC,YAAL,gBAAoBjB,KAAK,CAACkB,SAAN,EAApB;IACA,KAAKC,QAAL,gBAAgBnB,KAAK,CAACkB,SAAN,EAAhB;IACA,KAAKE,YAAL,GAAoB,KAAKA,YAAL,CAAkBC,IAAlB,CAAuB,IAAvB,CAApB;IACA,KAAKC,UAAL,GAAkB,KAAKA,UAAL,CAAgBD,IAAhB,CAAqB,IAArB,CAAlB;IACA,KAAKE,WAAL,GAAmB,KAAKA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JT;QAKE,QAAQ,EAAE,GALZ;QAME,KAAK,EAAE,CAAC,EAAD,EAAK,CAAL,CANT;QAOE,QAAQ,EAAE,CAPZ;QAQE,WAAW,EAAE,IARf;QASE,QAAQ,eAAE0B,QAAF,8CAAE,UAAUC,IATtB;QAUE,OAAO,EAAC;MAVV,GAWM,KAAKlH,KAAL,CAAWmH,YAXjB,GAaGN,OAbH,CADF;IAiBD;;IACD,OAAOA,OAAP;EACD;;EAEShB,eAAe,CACvBuB,oBADuB,EAER;IACf,uCACKA,oBADL,GAEK,KAAKpH,KAAL,CAAW4F,YAFhB;EAID;;AAvaqD;;;;gBAL3ChG,S,kBAMyC;EAClDyH,SAAS,EAAEhE,SADuC;EAElD1D,QAAQ,EAAE,KAFwC;EAGlDiF,KAAK,EAAEvB,SAH2C;EAIlD1C,QAAQ,EAAE,KAJwC;EAKlDoE,OAAO,EAAE,OALyC;EAMlDhD,aAAa,EAAE,KANmC;EAOlDyB,cAAc,EAAE,IAPkC;EAQlDxB,WAAW,EAAEqB,SARqC;EASlDD,2BAA2B,EAAE;AATqB,C;;eAwavCxD,S"}
|
1
|
+
{"version":3,"file":"BaseInput.js","names":["defaultBaseTranslations","required","BaseInput","React","Component","constructor","props","subscribe","guid","res","handleValueChange","value","state","isValid","errors","touched","defaultTouched","disabled","focused","handleValueChangeEnabled","containerRef","createRef","inputRef","handleChange","bind","handleBlur","handleFocus","setValid","focus","scrollTo","setInvalid","disableComponent","enableComponent","touch","unTouch","subscribeSelf","componentWillUnmount","ignoreContext","formContext","unSubscribe","componentId","componentDidUpdate","oldProps","oldState","validators","customValidators","domNode","ReactDOM","findDOMNode","current","scrollIntoView","behavior","setState","shouldComponentUpdate","nextProps","nextState","shouldUpdate","shallowEqual","reRendersWhenContextChanges","undefined","getValidationClass","extraErrors","showValidation","length","renderDefaultValidation","finalErrors","concat","filter","i","lastValidation","map","item","index","event","target","onTheFlightValidate","onChange","componentApi","validation","name","validationName","title","label","e","onBlur","touchOn","Object","assign","onFocus","getDisabled","updateCallback","renderLabel","touchable","tooltip","classNames","renderTooltip","renderTitle","initializing","translations","getTranslations","push","forEach","validator","validInner","Validators","EmailValidator","Validate","error","NumberValidator","LatitudeValidator","LongitudeValidator","UrlValidator","Error","customValidator","onErrorsChanged","content","Tippy","require","default","document","body","tooltipProps","_defaultTranslations","className"],"sources":["../../../../src/lib/components/base/input/BaseInput.tsx"],"sourcesContent":["// Libs\r\nimport * as React from 'react';\r\nimport * as ReactDOM from 'react-dom';\r\nimport type { TippyProps } from '@tippy.js/react';\r\n\r\n// Misc\r\nimport * as Validators from '../../../validators';\r\nimport guid from '../../utils/Guid';\r\nimport { FormContextProps } from '../../form/FormContext';\r\nimport { shallowEqual } from '../../utils/ShallowEqual';\r\nimport { Theme } from '../../../types/Theme';\r\nimport classNames from 'classnames';\r\n\r\nexport interface ComponentApi {\r\n focus: () => void;\r\n touch: () => void;\r\n unTouch: () => void;\r\n enableComponent: () => void;\r\n disableComponent: () => void;\r\n scrollTo: () => void;\r\n}\r\n\r\nexport type ValidationError = string | JSX.Element;\r\n\r\nexport type AllowedHtmlElements =\r\n | HTMLInputElement\r\n | HTMLSelectElement\r\n | HTMLTextAreaElement;\r\n\r\nexport const defaultBaseTranslations = {\r\n required: 'Required',\r\n};\r\n\r\nexport type BaseTranslations = Partial<typeof defaultBaseTranslations>;\r\n\r\nexport type BaseInputProps<\r\n HTMLType extends AllowedHtmlElements,\r\n TranslationsT extends BaseTranslations = BaseTranslations\r\n> = {\r\n theme?: Theme;\r\n id?: string;\r\n disabled?: boolean;\r\n className?: string;\r\n label?: string | JSX.Element;\r\n tooltip?: string | JSX.Element;\r\n tooltipProps?: TippyProps;\r\n value?: string;\r\n onChange?: (e: React.ChangeEvent<HTMLType>, isValid: boolean) => void;\r\n required?: boolean;\r\n customValidators?: Validators.IBaseValidator[];\r\n validators?: Validators.ValidatorTypes[];\r\n noValidate?: boolean;\r\n validationName?: string;\r\n touchOn?: 'focus' | 'blur';\r\n ignoreContext?: boolean;\r\n onTheFlightValidate?: (value: string) => boolean;\r\n onFocus?: (e: React.SyntheticEvent<{}>) => void;\r\n onBlur?: () => void;\r\n onSuggestionsClosed?: () => void;\r\n onSuggestionsOpened?: () => void;\r\n onClick?: (e: React.MouseEvent) => void;\r\n title?: string | JSX.Element;\r\n onKeyDown?: (e: React.KeyboardEvent<HTMLElement>) => void;\r\n errors?: ValidationError[];\r\n onErrorsChanged?: (errors: ValidationError[]) => void;\r\n showValidation?: boolean;\r\n reRendersWhenContextChanges?: boolean;\r\n defaultTouched?: boolean;\r\n translations?: TranslationsT;\r\n inputGroupClassName?: string;\r\n} & FormContextProps;\r\n\r\nexport interface BaseInputState {\r\n isValid: boolean;\r\n value: string;\r\n errors: ValidationError[];\r\n validator: undefined;\r\n touched: boolean;\r\n disabled: boolean;\r\n focused: boolean;\r\n handleValueChangeEnabled: boolean;\r\n}\r\n\r\nexport class BaseInput<\r\n P extends BaseInputProps<HTMLType, TranslationsT>,\r\n S extends BaseInputState,\r\n HTMLType extends AllowedHtmlElements,\r\n TranslationsT extends BaseTranslations = BaseTranslations\r\n> extends React.Component<P, S> implements ComponentApi {\r\n public static defaultProps: BaseInputProps<never> = {\r\n className: undefined,\r\n required: false,\r\n label: undefined,\r\n disabled: false,\r\n touchOn: 'focus',\r\n ignoreContext: false,\r\n showValidation: true,\r\n formContext: undefined,\r\n reRendersWhenContextChanges: false,\r\n };\r\n\r\n public componentId = guid();\r\n\r\n public inputRef: React.RefObject<HTMLType>;\r\n\r\n protected containerRef: React.RefObject<HTMLDivElement>;\r\n\r\n private lastValidation: JSX.Element[];\r\n\r\n constructor(props: P, subscribe: boolean = true) {\r\n super(props);\r\n const res = this.handleValueChange(this.props.value, true, [], props, true);\r\n this.state = {\r\n isValid: res.isValid,\r\n errors: res.errors,\r\n value: props.value ? props.value : '',\r\n touched: props.defaultTouched,\r\n disabled: false,\r\n focused: false,\r\n handleValueChangeEnabled: true,\r\n } as S;\r\n this.containerRef = React.createRef<HTMLDivElement>();\r\n this.inputRef = React.createRef<HTMLType>();\r\n this.handleChange = this.handleChange.bind(this);\r\n this.handleBlur = this.handleBlur.bind(this);\r\n this.handleFocus = this.handleFocus.bind(this);\r\n this.setValid = this.setValid.bind(this);\r\n this.focus = this.focus.bind(this);\r\n this.scrollTo = this.scrollTo.bind(this);\r\n this.setInvalid = this.setInvalid.bind(this);\r\n this.disableComponent = this.disableComponent.bind(this);\r\n this.enableComponent = this.enableComponent.bind(this);\r\n this.touch = this.touch.bind(this);\r\n this.unTouch = this.unTouch.bind(this);\r\n if (subscribe) {\r\n this.subscribeSelf(props);\r\n }\r\n }\r\n\r\n public componentWillUnmount() {\r\n if (!this.props.ignoreContext) {\r\n this.props.formContext &&\r\n this.props.formContext.unSubscribe(this.componentId);\r\n }\r\n }\r\n\r\n public componentDidUpdate(oldProps: P, oldState: S) {\r\n if (\r\n oldProps.value !== this.props.value ||\r\n oldProps.validators !== this.props.validators ||\r\n oldProps.customValidators !== this.props.customValidators ||\r\n oldProps.required !== this.props.required\r\n ) {\r\n this.handleValueChange(this.props.value, true, [], this.props);\r\n }\r\n }\r\n\r\n public scrollTo() {\r\n const domNode: HTMLDivElement = ReactDOM.findDOMNode(\r\n (this.containerRef as React.RefObject<HTMLDivElement>).current\r\n ) as HTMLDivElement;\r\n domNode && domNode.scrollIntoView({ behavior: 'smooth' });\r\n }\r\n\r\n public touch() {\r\n this.setState({ touched: true });\r\n this.handleValueChange(this.state.value || '');\r\n }\r\n\r\n public unTouch() {\r\n this.setState({ touched: false });\r\n }\r\n\r\n public disableComponent() {\r\n this.setState({ disabled: true });\r\n }\r\n\r\n public enableComponent() {\r\n this.setState({ disabled: false });\r\n }\r\n\r\n public focus() {\r\n if (this.inputRef) {\r\n const domNode: HTMLElement = ReactDOM.findDOMNode(\r\n (this.inputRef as React.RefObject<HTMLElement>).current\r\n ) as HTMLElement;\r\n domNode && domNode.focus();\r\n }\r\n this.touch();\r\n }\r\n\r\n public shouldComponentUpdate(nextProps: P, nextState: S) {\r\n let shouldUpdate =\r\n !shallowEqual(\r\n this.props,\r\n nextProps,\r\n !this.props.reRendersWhenContextChanges ? 'formContext' : undefined\r\n ) || !shallowEqual(this.state, nextState);\r\n return shouldUpdate;\r\n }\r\n\r\n protected getValidationClass(extraErrors?: ValidationError[]) {\r\n if (!this.props.showValidation || !this.state.touched) {\r\n return 'validation__success';\r\n }\r\n return this.state.isValid &&\r\n (!this.props.errors || this.props.errors.length === 0) &&\r\n (!this.state.errors || this.state.errors.length === 0) &&\r\n (!extraErrors || extraErrors.length === 0)\r\n ? 'validation__success'\r\n : 'validation__error';\r\n }\r\n\r\n protected renderDefaultValidation(extraErrors?: ValidationError[]) {\r\n if (this.props.disabled) {\r\n return null;\r\n }\r\n if (!this.props.showValidation) {\r\n return null;\r\n }\r\n let finalErrors: ValidationError[] = this.state.errors;\r\n if (!finalErrors) {\r\n finalErrors = [];\r\n }\r\n if (extraErrors) {\r\n finalErrors = finalErrors.concat(extraErrors);\r\n }\r\n if (this.props.errors) {\r\n finalErrors = finalErrors.concat(this.props.errors);\r\n }\r\n finalErrors = finalErrors.filter(i => i);\r\n if (finalErrors.length > 0) {\r\n this.lastValidation = finalErrors.map((item, index) => (\r\n <li key={index} className=\"validation__item\">\r\n {item}\r\n </li>\r\n ));\r\n }\r\n return (\r\n <div className=\"validation__container\">\r\n <ul className=\"validation__ul\">{this.lastValidation}</ul>\r\n </div>\r\n );\r\n }\r\n\r\n protected handleChange(\r\n event: React.ChangeEvent<HTMLType>,\r\n isValid?: boolean,\r\n errors: ValidationError[] = []\r\n ) {\r\n let value = event.target.value;\r\n if (\r\n !this.props.onTheFlightValidate ||\r\n (this.props.onTheFlightValidate && this.props.onTheFlightValidate(value))\r\n ) {\r\n const res = this.handleValueChange(value, isValid, errors);\r\n if (this.props.onChange) {\r\n this.props.onChange(event, res.isValid);\r\n }\r\n }\r\n }\r\n\r\n protected subscribeSelf(props: P) {\r\n if (!props.ignoreContext && props.formContext) {\r\n props.formContext.subscribe(this.componentId, {\r\n componentApi: {\r\n disableComponent: this.disableComponent,\r\n enableComponent: this.enableComponent,\r\n touch: this.touch,\r\n unTouch: this.unTouch,\r\n scrollTo: this.scrollTo,\r\n focus: this.focus,\r\n },\r\n validation: {\r\n isValid: this.state.isValid,\r\n errors: this.state.errors,\r\n name: this.props.validationName\r\n ? this.props.validationName\r\n : this.props.title\r\n ? this.props.title\r\n : this.props.label,\r\n },\r\n });\r\n }\r\n }\r\n\r\n protected handleBlur(e: React.FocusEvent<HTMLType>) {\r\n this.props.onBlur && this.props.onBlur();\r\n let state = { focused: false };\r\n if (!this.state.touched && this.props.touchOn === 'blur') {\r\n state = Object.assign(state, { touched: true });\r\n this.handleValueChange(this.state.value);\r\n }\r\n this.setState(state);\r\n }\r\n\r\n protected handleFocus(e: React.FocusEvent<HTMLType>) {\r\n if (!this.props.disabled) {\r\n this.props.onFocus && this.props.onFocus(e);\r\n let state = { focused: true };\r\n if (!this.state.touched && this.props.touchOn === 'focus') {\r\n state = Object.assign(state, { touched: true });\r\n this.handleValueChange(this.state.value);\r\n }\r\n this.setState(state);\r\n }\r\n }\r\n\r\n protected getDisabled() {\r\n return this.state.disabled ? this.state.disabled : this.props.disabled;\r\n }\r\n\r\n protected setValid() {\r\n this.setState(\r\n () => ({ isValid: true, errors: [] }),\r\n () => {\r\n if (!this.props.ignoreContext) {\r\n this.props.formContext &&\r\n this.props.formContext.updateCallback(this.componentId, {\r\n validation: {\r\n isValid: true,\r\n errors: [],\r\n },\r\n });\r\n }\r\n }\r\n );\r\n }\r\n\r\n protected setInvalid(errors: ValidationError[] = []) {\r\n this.setState(\r\n () => ({ isValid: false, errors }),\r\n () => {\r\n if (!this.props.ignoreContext) {\r\n this.props.formContext &&\r\n this.props.formContext.updateCallback(this.componentId, {\r\n validation: {\r\n isValid: false,\r\n errors: errors,\r\n },\r\n });\r\n }\r\n }\r\n );\r\n }\r\n\r\n protected renderLabel(touchable: boolean = false) {\r\n if (!this.props.tooltip || (this.props.tooltip && this.props.title)) {\r\n return (\r\n <span\r\n className={classNames('w-100', { 'label--no-touch': !touchable })}\r\n >\r\n {this.props.label}\r\n </span>\r\n );\r\n }\r\n return (\r\n <React.Fragment>\r\n <span className={touchable ? '' : 'label--no-touch'}>\r\n {this.props.label}\r\n </span>\r\n {this.renderTooltip()}\r\n </React.Fragment>\r\n );\r\n }\r\n\r\n protected renderTitle() {\r\n if (!this.props.tooltip) {\r\n return this.props.title;\r\n }\r\n return (\r\n <React.Fragment>\r\n {this.props.title}\r\n {this.renderTooltip()}\r\n </React.Fragment>\r\n );\r\n }\r\n\r\n protected handleValueChange(\r\n value: string,\r\n isValid: boolean = true,\r\n errors: ValidationError[] = [],\r\n props: P = this.props,\r\n initializing: boolean = false\r\n ): {\r\n isValid: boolean;\r\n errors: ValidationError[];\r\n } {\r\n if (!initializing && !this.state.handleValueChangeEnabled) {\r\n return { isValid, errors: [] };\r\n }\r\n if (props.required && !value) {\r\n const translations = this.getTranslations(defaultBaseTranslations);\r\n errors.push(translations.required);\r\n isValid = false;\r\n } else {\r\n if (!props.required && !value) {\r\n isValid = true;\r\n } else {\r\n if (props.validators) {\r\n isValid = true;\r\n props.validators.forEach(validator => {\r\n let validInner = false;\r\n switch (validator) {\r\n case 'email':\r\n validInner = new Validators.EmailValidator().Validate(\r\n value,\r\n props.required,\r\n error => errors.push(error)\r\n );\r\n break;\r\n case 'number':\r\n validInner = new Validators.NumberValidator().Validate(\r\n value,\r\n props.required,\r\n error => errors.push(error)\r\n );\r\n break;\r\n case 'latitude':\r\n validInner = new Validators.LatitudeValidator().Validate(\r\n value,\r\n props.required,\r\n error => errors.push(error)\r\n );\r\n break;\r\n case 'longitude':\r\n validInner = new Validators.LongitudeValidator().Validate(\r\n value,\r\n props.required,\r\n error => errors.push(error)\r\n );\r\n break;\r\n case 'url':\r\n validInner = new Validators.UrlValidator().Validate(\r\n value,\r\n props.required,\r\n error => errors.push(error)\r\n );\r\n break;\r\n default:\r\n throw new Error(`Validator ${validator} not implemented`);\r\n }\r\n if (isValid && !validInner) {\r\n isValid = validInner;\r\n }\r\n });\r\n }\r\n if (props.customValidators) {\r\n props.customValidators.forEach(customValidator => {\r\n let validInner = false;\r\n validInner = customValidator.Validate(\r\n value,\r\n props.required,\r\n error => errors.push(error)\r\n );\r\n if (isValid && !validInner) {\r\n isValid = validInner;\r\n }\r\n });\r\n }\r\n }\r\n }\r\n props.onErrorsChanged && props.onErrorsChanged(errors);\r\n if (!initializing) {\r\n this.setState({ value, isValid, errors });\r\n if (!props.ignoreContext) {\r\n props.formContext &&\r\n props.formContext.updateCallback(this.componentId, {\r\n validation: {\r\n isValid: isValid,\r\n errors: errors,\r\n },\r\n });\r\n }\r\n }\r\n return { isValid, errors };\r\n }\r\n\r\n protected renderTooltip(\r\n content: JSX.Element = <span className=\"label--help-icon\">?</span>\r\n ) {\r\n if (this.props.tooltip) {\r\n const Tippy = require('@tippy.js/react').default;\r\n return (\r\n <Tippy\r\n content={this.props.tooltip}\r\n placement=\"bottom\"\r\n animation=\"scale-subtle\"\r\n arrow={false}\r\n duration={200}\r\n delay={[75, 0]}\r\n distance={8}\r\n interactive={true}\r\n appendTo={document?.body}\r\n trigger=\"mouseenter focus\"\r\n {...this.props.tooltipProps}\r\n >\r\n {content}\r\n </Tippy>\r\n );\r\n }\r\n return content;\r\n }\r\n\r\n protected getTranslations(\r\n _defaultTranslations: BaseTranslations\r\n ): TranslationsT {\r\n return {\r\n ..._defaultTranslations,\r\n ...this.props.translations,\r\n };\r\n }\r\n}\r\nexport default BaseInput;\r\n"],"mappings":";;;;;;;AACA;;AACA;;AAIA;;AACA;;AAEA;;AAEA;;;;;;;;;;;;;;;;AAkBO,MAAMA,uBAAuB,GAAG;EACrCC,QAAQ,EAAE;AAD2B,CAAhC;;;AAsDA,MAAMC,SAAN,SAKGC,KAAK,CAACC,SALT,CAKiD;EAqBtDC,WAAW,CAACC,KAAD,EAAsC;IAAA,IAA3BC,SAA2B,uEAAN,IAAM;IAC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S,EAAEhE,SADuC;EAElD1D,QAAQ,EAAE,KAFwC;EAGlDiF,KAAK,EAAEvB,SAH2C;EAIlD1C,QAAQ,EAAE,KAJwC;EAKlDoE,OAAO,EAAE,OALyC;EAMlDhD,aAAa,EAAE,KANmC;EAOlDyB,cAAc,EAAE,IAPkC;EAQlDxB,WAAW,EAAEqB,SARqC;EASlDD,2BAA2B,EAAE;AATqB,C;;eAwavCxD,S"}
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import * as React from 'react';
|
2
|
-
import { TippyProps } from '@tippy.js/react';
|
2
|
+
import type { TippyProps } from '@tippy.js/react';
|
3
3
|
import { ThemeContextProps } from '../themeProvider/ThemeContext';
|
4
4
|
export declare type ButtonTypes = 'primary' | 'success' | 'error' | 'warning' | 'info' | 'gray' | 'white' | 'none';
|
5
5
|
export declare type ButtonComponentProps = {
|
@@ -33,6 +33,7 @@ export declare type ButtonProps = React.PropsWithChildren<{
|
|
33
33
|
dropdown?: boolean;
|
34
34
|
Component?: React.FC<ButtonComponentProps>;
|
35
35
|
tooltip?: JSX.Element | string;
|
36
|
+
disableTooltip?: boolean;
|
36
37
|
tooltipProps?: TippyProps;
|
37
38
|
preventsDefault?: boolean;
|
38
39
|
} & ThemeContextProps>;
|
@@ -71,6 +72,7 @@ declare const _default: React.ForwardRefExoticComponent<{
|
|
71
72
|
dropdown?: boolean;
|
72
73
|
Component?: React.FC<ButtonComponentProps>;
|
73
74
|
tooltip?: string | JSX.Element;
|
75
|
+
disableTooltip?: boolean;
|
74
76
|
tooltipProps?: TippyProps;
|
75
77
|
preventsDefault?: boolean;
|
76
78
|
} & ThemeContextProps & {
|
@@ -9,6 +9,12 @@ var React = _interopRequireWildcard(require("react"));
|
|
9
9
|
|
10
10
|
var _withThemeContext = require("../themeProvider/withThemeContext");
|
11
11
|
|
12
|
+
var _reactInk = _interopRequireDefault(require("react-ink"));
|
13
|
+
|
14
|
+
var _classnames = _interopRequireDefault(require("classnames"));
|
15
|
+
|
16
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
17
|
+
|
12
18
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
13
19
|
|
14
20
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
@@ -21,11 +27,6 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
|
|
21
27
|
|
22
28
|
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
23
29
|
|
24
|
-
var Ink = require('react-ink');
|
25
|
-
|
26
|
-
var classNames = require('classnames'); // Misc
|
27
|
-
|
28
|
-
|
29
30
|
const DefaultButtonComponent = /*#__PURE__*/React.forwardRef((props, ref) => /*#__PURE__*/React.createElement("button", _extends({
|
30
31
|
ref: ref // tslint:disable-next-line:no-any
|
31
32
|
|
@@ -53,7 +54,7 @@ class Button extends React.PureComponent {
|
|
53
54
|
var _this$props$buttonPro;
|
54
55
|
|
55
56
|
const disabled = this.props.disabled || this.props.disableAfterClick && this.state.disabledAfterClick;
|
56
|
-
let btnClassName =
|
57
|
+
let btnClassName = (0, _classnames.default)(['guestbell-btn', this.getButtonClassName(), this.props.className, {
|
57
58
|
['guestbell-btn--disabled']: disabled
|
58
59
|
}, {
|
59
60
|
['guestbell-btn--circular']: this.props.circular
|
@@ -85,9 +86,9 @@ class Button extends React.PureComponent {
|
|
85
86
|
}),
|
86
87
|
className: btnClassName,
|
87
88
|
style: this.props.style
|
88
|
-
}), !this.props.noRipples && !disabled &&
|
89
|
+
}), !this.props.noRipples && !disabled && _reactInk.default && /*#__PURE__*/React.createElement(_reactInk.default, null), this.props.children);
|
89
90
|
|
90
|
-
if (this.props.tooltip) {
|
91
|
+
if (this.props.tooltip && !this.props.disableTooltip) {
|
91
92
|
var _document;
|
92
93
|
|
93
94
|
const Tippy = require('@tippy.js/react').default;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"Button.js","names":["Ink","require","classNames","DefaultButtonComponent","React","forwardRef","props","ref","buttonProps","id","className","onClick","style","children","Button","PureComponent","constructor","handleClick","bind","state","disabledAfterClick","render","disabled","disableAfterClick","btnClassName","getButtonClassName","circular","small","noShadow","blank","unobtrusive","outlined","dropdown","icon","hero","text","button","tabIndex","noRipples","tooltip","Tippy","default","document","body","tooltipProps","componentWillUnmount","clearTimeout","preventMultipleClickTimer","e","preventsDefault","preventDefault","disableAfterClickMs","setState","setTimeout","type","Component","role","withThemeContext"],"sources":["../../../src/lib/components/button/Button.tsx"],"sourcesContent":["// Libs\r\nimport * as React from 'react';\r\nimport { TippyProps } from '@tippy.js/react';\r\nimport { withThemeContext } from '../themeProvider/withThemeContext';\r\nimport { ThemeContextProps } from '../themeProvider/ThemeContext';\r\nvar Ink = require('react-ink');\r\nvar classNames = require('classnames');\r\n\r\n// Misc\r\n\r\nexport type ButtonTypes =\r\n | 'primary'\r\n | 'success'\r\n | 'error'\r\n | 'warning'\r\n | 'info'\r\n | 'gray'\r\n | 'white'\r\n | 'none';\r\n\r\nexport type ButtonComponentProps = {\r\n id?: string;\r\n onClick: (e: React.MouseEvent<HTMLElement>) => void;\r\n className: string;\r\n buttonProps: React.ButtonHTMLAttributes<HTMLButtonElement>;\r\n children: React.ReactNode;\r\n style: React.CSSProperties;\r\n};\r\n\r\nexport type ButtonProps = React.PropsWithChildren<\r\n {\r\n id?: string;\r\n onClick?: (e: React.MouseEvent<HTMLButtonElement>) => void;\r\n style?: React.CSSProperties;\r\n className?: string;\r\n disabled?: boolean;\r\n type?: ButtonTypes;\r\n circular?: boolean;\r\n noRipples?: boolean;\r\n small?: boolean;\r\n icon?: boolean;\r\n outlined?: boolean;\r\n disableAfterClickMs?: number;\r\n disableAfterClick?: boolean;\r\n buttonProps?: React.ButtonHTMLAttributes<HTMLButtonElement>;\r\n text?: boolean;\r\n hero?: boolean;\r\n noShadow?: boolean;\r\n blank?: boolean;\r\n unobtrusive?: boolean;\r\n dropdown?: boolean;\r\n Component?: React.FC<ButtonComponentProps>;\r\n tooltip?: JSX.Element | string;\r\n tooltipProps?: TippyProps;\r\n preventsDefault?: boolean;\r\n } & ThemeContextProps\r\n>;\r\n\r\nexport interface ButtonState {\r\n disabledAfterClick: boolean;\r\n}\r\n\r\nconst DefaultButtonComponent: React.FC<ButtonComponentProps> = React.forwardRef(\r\n (props, ref) => (\r\n <button\r\n ref={ref}\r\n // tslint:disable-next-line:no-any\r\n {...((props.buttonProps ? props.buttonProps : {}) as any)}\r\n {...(props.id && { id: props.id })}\r\n className={props.className}\r\n onClick={props.onClick}\r\n style={props.style}\r\n >\r\n {props.children}\r\n </button>\r\n )\r\n);\r\n\r\nexport class Button extends React.PureComponent<ButtonProps, ButtonState> {\r\n public static defaultProps: ButtonProps = {\r\n disabled: false,\r\n className: '',\r\n onClick: () => null,\r\n circular: false,\r\n noRipples: false,\r\n small: false,\r\n disableAfterClickMs: 100,\r\n disableAfterClick: false,\r\n Component: DefaultButtonComponent,\r\n buttonProps: {\r\n type: 'button',\r\n role: 'button',\r\n tabIndex: 0,\r\n },\r\n type: 'none',\r\n preventsDefault: true,\r\n };\r\n\r\n private preventMultipleClickTimer: number;\r\n\r\n constructor(props: ButtonProps) {\r\n super(props);\r\n this.handleClick = this.handleClick.bind(this);\r\n this.state = {\r\n disabledAfterClick: false,\r\n };\r\n }\r\n\r\n public render() {\r\n const disabled =\r\n this.props.disabled ||\r\n (this.props.disableAfterClick && this.state.disabledAfterClick);\r\n let btnClassName = classNames([\r\n 'guestbell-btn',\r\n this.getButtonClassName(),\r\n this.props.className,\r\n { ['guestbell-btn--disabled']: disabled },\r\n { ['guestbell-btn--circular']: this.props.circular },\r\n { ['guestbell-btn--small']: this.props.small },\r\n { ['guestbell-btn--no-shadow']: this.props.noShadow },\r\n { ['guestbell-btn--blank']: this.props.blank },\r\n { ['guestbell-btn--unobtrusive']: this.props.unobtrusive },\r\n { ['guestbell-btn--outlined']: this.props.outlined },\r\n { ['guestbell-btn--dropdown']: this.props.dropdown },\r\n { ['guestbell-btn--icon']: this.props.icon },\r\n { ['guestbell-btn--hero']: this.props.hero },\r\n { ['guestbell-btn--text']: this.props.text },\r\n ]);\r\n const button = (\r\n <this.props.Component\r\n {...(this.props.id && { id: this.props.id })}\r\n onClick={this.handleClick}\r\n buttonProps={{\r\n ...this.props.buttonProps,\r\n tabIndex: !disabled ? this.props.buttonProps?.tabIndex : -1,\r\n }}\r\n className={btnClassName}\r\n style={this.props.style}\r\n >\r\n {!this.props.noRipples && !disabled && Ink && <Ink />}\r\n {this.props.children}\r\n </this.props.Component>\r\n );\r\n if (this.props.tooltip) {\r\n const Tippy = require('@tippy.js/react').default;\r\n return (\r\n <Tippy\r\n content={this.props.tooltip}\r\n placement=\"bottom\"\r\n animation=\"scale-subtle\"\r\n arrow={false}\r\n duration={200}\r\n delay={[75, 0]}\r\n distance={8}\r\n interactive={true}\r\n appendTo={document?.body}\r\n {...this.props.tooltipProps}\r\n >\r\n {button}\r\n </Tippy>\r\n );\r\n }\r\n return button;\r\n }\r\n\r\n public componentWillUnmount() {\r\n clearTimeout(this.preventMultipleClickTimer);\r\n }\r\n\r\n private handleClick(e: React.MouseEvent<HTMLButtonElement>) {\r\n if (this.props.preventsDefault) {\r\n e.preventDefault();\r\n }\r\n if (!this.state.disabledAfterClick && !this.props.disabled) {\r\n this.props.onClick && this.props.onClick(e);\r\n if (this.props.disableAfterClickMs !== 0) {\r\n this.setState({ disabledAfterClick: true });\r\n this.preventMultipleClickTimer = (setTimeout(() => {\r\n this.setState({ disabledAfterClick: false });\r\n }, this.props.disableAfterClickMs) as unknown) as number;\r\n }\r\n }\r\n }\r\n\r\n private getButtonClassName() {\r\n return this.props.type && 'guestbell-btn-' + this.props.type;\r\n }\r\n}\r\nexport default withThemeContext<ButtonProps, InstanceType<typeof Button>>(\r\n Button,\r\n 'button'\r\n);\r\n"],"mappings":";;;;;;;AACA;;AAEA;;;;;;;;;;;;;;AAEA,IAAIA,GAAG,GAAGC,OAAO,CAAC,WAAD,CAAjB;;AACA,IAAIC,UAAU,GAAGD,OAAO,CAAC,YAAD,CAAxB,C,CAEA;;;AAsDA,MAAME,sBAAsD,gBAAGC,KAAK,CAACC,UAAN,CAC7D,CAACC,KAAD,EAAQC,GAAR,kBACE;EACE,GAAG,EAAEA,GADP,CAEE;;AAFF,GAGQD,KAAK,CAACE,WAAN,GAAoBF,KAAK,CAACE,WAA1B,GAAwC,EAHhD,EAIOF,KAAK,CAACG,EAAN,IAAY;EAAEA,EAAE,EAAEH,KAAK,CAACG;AAAZ,CAJnB;EAKE,SAAS,EAAEH,KAAK,CAACI,SALnB;EAME,OAAO,EAAEJ,KAAK,CAACK,OANjB;EAOE,KAAK,EAAEL,KAAK,CAACM;AAPf,IASGN,KAAK,CAACO,QATT,CAF2D,CAA/D;;AAgBO,MAAMC,MAAN,SAAqBV,KAAK,CAACW,aAA3B,CAAmE;EAsBxEC,WAAW,CAACV,KAAD,EAAqB;IAC9B,MAAMA,KAAN;;IAD8B;;IAE9B,KAAKW,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K/B,KAAL,CAAWC,kBAAZ,IAAkC,CAAC,KAAKd,KAAL,CAAWgB,QAAlD,EAA4D;MAC1D,KAAKhB,KAAL,CAAWK,OAAX,IAAsB,KAAKL,KAAL,CAAWK,OAAX,CAAmBqC,CAAnB,CAAtB;;MACA,IAAI,KAAK1C,KAAL,CAAW6C,mBAAX,KAAmC,CAAvC,EAA0C;QACxC,KAAKC,QAAL,CAAc;UAAEhC,kBAAkB,EAAE;QAAtB,CAAd;QACA,KAAK2B,yBAAL,GAAkCM,UAAU,CAAC,MAAM;UACjD,KAAKD,QAAL,CAAc;YAAEhC,kBAAkB,EAAE;UAAtB,CAAd;QACD,CAF2C,EAEzC,KAAKd,KAAL,CAAW6C,mBAF8B,CAA5C;MAGD;IACF;EACF;;EAEO1B,kBAAkB,GAAG;IAC3B,OAAO,KAAKnB,KAAL,CAAWgD,IAAX,IAAmB,mBAAmB,KAAKhD,KAAL,CAAWgD,IAAxD;EACD;;AA5GuE;;;;gBAA7DxC,M,kBAC+B;EACxCQ,QAAQ,EAAE,KAD8B;EAExCZ,SAAS,EAAE,EAF6B;EAGxCC,OAAO,EAAE,MAAM,IAHyB;EAIxCe,QAAQ,EAAE,KAJ8B;EAKxCY,SAAS,EAAE,KAL6B;EAMxCX,KAAK,EAAE,KANiC;EAOxCwB,mBAAmB,EAAE,GAPmB;EAQxC5B,iBAAiB,EAAE,KARqB;EASxCgC,SAAS,EAAEpD,sBAT6B;EAUxCK,WAAW,EAAE;IACX8C,IAAI,EAAE,QADK;IAEXE,IAAI,EAAE,QAFK;IAGXnB,QAAQ,EAAE;EAHC,CAV2B;EAexCiB,IAAI,EAAE,MAfkC;EAgBxCL,eAAe,EAAE;AAhBuB,C;;eA6G7B,IAAAQ,kCAAA,EACb3C,MADa,EAEb,QAFa,C"}
|
1
|
+
{"version":3,"file":"Button.js","names":["DefaultButtonComponent","React","forwardRef","props","ref","buttonProps","id","className","onClick","style","children","Button","PureComponent","constructor","handleClick","bind","state","disabledAfterClick","render","disabled","disableAfterClick","btnClassName","classNames","getButtonClassName","circular","small","noShadow","blank","unobtrusive","outlined","dropdown","icon","hero","text","button","tabIndex","noRipples","Ink","tooltip","disableTooltip","Tippy","require","default","document","body","tooltipProps","componentWillUnmount","clearTimeout","preventMultipleClickTimer","e","preventsDefault","preventDefault","disableAfterClickMs","setState","setTimeout","type","Component","role","withThemeContext"],"sources":["../../../src/lib/components/button/Button.tsx"],"sourcesContent":["// Libs\r\nimport * as React from 'react';\r\nimport type { TippyProps } from '@tippy.js/react';\r\nimport { withThemeContext } from '../themeProvider/withThemeContext';\r\nimport { ThemeContextProps } from '../themeProvider/ThemeContext';\r\nimport Ink from 'react-ink';\r\nimport classNames from 'classnames';\r\n\r\n// Misc\r\n\r\nexport type ButtonTypes =\r\n | 'primary'\r\n | 'success'\r\n | 'error'\r\n | 'warning'\r\n | 'info'\r\n | 'gray'\r\n | 'white'\r\n | 'none';\r\n\r\nexport type ButtonComponentProps = {\r\n id?: string;\r\n onClick: (e: React.MouseEvent<HTMLElement>) => void;\r\n className: string;\r\n buttonProps: React.ButtonHTMLAttributes<HTMLButtonElement>;\r\n children: React.ReactNode;\r\n style: React.CSSProperties;\r\n};\r\n\r\nexport type ButtonProps = React.PropsWithChildren<\r\n {\r\n id?: string;\r\n onClick?: (e: React.MouseEvent<HTMLButtonElement>) => void;\r\n style?: React.CSSProperties;\r\n className?: string;\r\n disabled?: boolean;\r\n type?: ButtonTypes;\r\n circular?: boolean;\r\n noRipples?: boolean;\r\n small?: boolean;\r\n icon?: boolean;\r\n outlined?: boolean;\r\n disableAfterClickMs?: number;\r\n disableAfterClick?: boolean;\r\n buttonProps?: React.ButtonHTMLAttributes<HTMLButtonElement>;\r\n text?: boolean;\r\n hero?: boolean;\r\n noShadow?: boolean;\r\n blank?: boolean;\r\n unobtrusive?: boolean;\r\n dropdown?: boolean;\r\n Component?: React.FC<ButtonComponentProps>;\r\n tooltip?: JSX.Element | string;\r\n disableTooltip?: boolean;\r\n tooltipProps?: TippyProps;\r\n preventsDefault?: boolean;\r\n } & ThemeContextProps\r\n>;\r\n\r\nexport interface ButtonState {\r\n disabledAfterClick: boolean;\r\n}\r\n\r\nconst DefaultButtonComponent: React.FC<ButtonComponentProps> = React.forwardRef(\r\n (props, ref) => (\r\n <button\r\n ref={ref}\r\n // tslint:disable-next-line:no-any\r\n {...((props.buttonProps ? props.buttonProps : {}) as any)}\r\n {...(props.id && { id: props.id })}\r\n className={props.className}\r\n onClick={props.onClick}\r\n style={props.style}\r\n >\r\n {props.children}\r\n </button>\r\n )\r\n);\r\n\r\nexport class Button extends React.PureComponent<ButtonProps, ButtonState> {\r\n public static defaultProps: ButtonProps = {\r\n disabled: false,\r\n className: '',\r\n onClick: () => null,\r\n circular: false,\r\n noRipples: false,\r\n small: false,\r\n disableAfterClickMs: 100,\r\n disableAfterClick: false,\r\n Component: DefaultButtonComponent,\r\n buttonProps: {\r\n type: 'button',\r\n role: 'button',\r\n tabIndex: 0,\r\n },\r\n type: 'none',\r\n preventsDefault: true,\r\n };\r\n\r\n private preventMultipleClickTimer: number;\r\n\r\n constructor(props: ButtonProps) {\r\n super(props);\r\n this.handleClick = this.handleClick.bind(this);\r\n this.state = {\r\n disabledAfterClick: false,\r\n };\r\n }\r\n\r\n public render() {\r\n const disabled =\r\n this.props.disabled ||\r\n (this.props.disableAfterClick && this.state.disabledAfterClick);\r\n let btnClassName = classNames([\r\n 'guestbell-btn',\r\n this.getButtonClassName(),\r\n this.props.className,\r\n { ['guestbell-btn--disabled']: disabled },\r\n { ['guestbell-btn--circular']: this.props.circular },\r\n { ['guestbell-btn--small']: this.props.small },\r\n { ['guestbell-btn--no-shadow']: this.props.noShadow },\r\n { ['guestbell-btn--blank']: this.props.blank },\r\n { ['guestbell-btn--unobtrusive']: this.props.unobtrusive },\r\n { ['guestbell-btn--outlined']: this.props.outlined },\r\n { ['guestbell-btn--dropdown']: this.props.dropdown },\r\n { ['guestbell-btn--icon']: this.props.icon },\r\n { ['guestbell-btn--hero']: this.props.hero },\r\n { ['guestbell-btn--text']: this.props.text },\r\n ]);\r\n const button = (\r\n <this.props.Component\r\n {...(this.props.id && { id: this.props.id })}\r\n onClick={this.handleClick}\r\n buttonProps={{\r\n ...this.props.buttonProps,\r\n tabIndex: !disabled ? this.props.buttonProps?.tabIndex : -1,\r\n }}\r\n className={btnClassName}\r\n style={this.props.style}\r\n >\r\n {!this.props.noRipples && !disabled && Ink && <Ink />}\r\n {this.props.children}\r\n </this.props.Component>\r\n );\r\n if (this.props.tooltip && !this.props.disableTooltip) {\r\n const Tippy = require('@tippy.js/react').default;\r\n return (\r\n <Tippy\r\n content={this.props.tooltip}\r\n placement=\"bottom\"\r\n animation=\"scale-subtle\"\r\n arrow={false}\r\n duration={200}\r\n delay={[75, 0]}\r\n distance={8}\r\n interactive={true}\r\n appendTo={document?.body}\r\n {...this.props.tooltipProps}\r\n >\r\n {button}\r\n </Tippy>\r\n );\r\n }\r\n return button;\r\n }\r\n\r\n public componentWillUnmount() {\r\n clearTimeout(this.preventMultipleClickTimer);\r\n }\r\n\r\n private handleClick(e: React.MouseEvent<HTMLButtonElement>) {\r\n if (this.props.preventsDefault) {\r\n e.preventDefault();\r\n }\r\n if (!this.state.disabledAfterClick && !this.props.disabled) {\r\n this.props.onClick && this.props.onClick(e);\r\n if (this.props.disableAfterClickMs !== 0) {\r\n this.setState({ disabledAfterClick: true });\r\n this.preventMultipleClickTimer = (setTimeout(() => {\r\n this.setState({ disabledAfterClick: false });\r\n }, this.props.disableAfterClickMs) as unknown) as number;\r\n }\r\n }\r\n }\r\n\r\n private getButtonClassName() {\r\n return this.props.type && 'guestbell-btn-' + this.props.type;\r\n }\r\n}\r\nexport default withThemeContext<ButtonProps, InstanceType<typeof Button>>(\r\n Button,\r\n 'button'\r\n);\r\n"],"mappings":";;;;;;;AACA;;AAEA;;AAEA;;AACA;;;;;;;;;;;;;;;;AAyDA,MAAMA,sBAAsD,gBAAGC,KAAK,CAACC,UAAN,CAC7D,CAACC,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AAO,EAAE,MAAM,IAHyB;EAIxCgB,QAAQ,EAAE,KAJ8B;EAKxCY,SAAS,EAAE,KAL6B;EAMxCX,KAAK,EAAE,KANiC;EAOxC2B,mBAAmB,EAAE,GAPmB;EAQxChC,iBAAiB,EAAE,KARqB;EASxCoC,SAAS,EAAExD,sBAT6B;EAUxCK,WAAW,EAAE;IACXkD,IAAI,EAAE,QADK;IAEXE,IAAI,EAAE,QAFK;IAGXtB,QAAQ,EAAE;EAHC,CAV2B;EAexCoB,IAAI,EAAE,MAfkC;EAgBxCL,eAAe,EAAE;AAhBuB,C;;eA6G7B,IAAAQ,kCAAA,EACb/C,MADa,EAEb,QAFa,C"}
|
@@ -11,6 +11,8 @@ var _InputGroup = _interopRequireDefault(require("../inputGroup/InputGroup"));
|
|
11
11
|
|
12
12
|
var _BaseInput = require("../base/input/BaseInput");
|
13
13
|
|
14
|
+
var _classnames = _interopRequireDefault(require("classnames"));
|
15
|
+
|
14
16
|
var _withFormContext = require("../form/withFormContext");
|
15
17
|
|
16
18
|
var _withThemeContext = require("../themeProvider/withThemeContext");
|
@@ -25,8 +27,6 @@ function _extends() { _extends = Object.assign ? Object.assign.bind() : function
|
|
25
27
|
|
26
28
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
27
29
|
|
28
|
-
var classNames = require('classnames');
|
29
|
-
|
30
30
|
class CheckboxRaw extends _BaseInput.BaseInput {
|
31
31
|
constructor(props) {
|
32
32
|
super(props, false);
|
@@ -85,7 +85,7 @@ class CheckboxRaw extends _BaseInput.BaseInput {
|
|
85
85
|
}
|
86
86
|
|
87
87
|
render() {
|
88
|
-
const containerClassName =
|
88
|
+
const containerClassName = (0, _classnames.default)(['input__base checkbox-input', this.getValidationClass(), this.props.className, {
|
89
89
|
['checkbox-input--with-label']: Boolean(this.props.label)
|
90
90
|
}, {
|
91
91
|
['checkbox-input--disabled']: this.props.disabled
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"Checkbox.js","names":["classNames","require","CheckboxRaw","BaseInput","constructor","props","state","Object","assign","checked","Boolean","isValid","required","errors","getTranslations","defaultBaseTranslations","handleChecked","bind","handleKeyDown","subscribeSelf","componentDidMount","finalIndeterminate","supportsIndeterminate","inputRef","current","indeterminate","componentDidUpdate","oldProps","undefined","setState","setValid","setInvalid","render","containerClassName","getValidationClass","className","label","disabled","input","id","value","handleBlur","handleFocus","title","tooltip","inputGroupClassName","containerRef","renderTooltip","renderDefaultValidation","renderLabel","e","onChecked","key","click","defaultProps","Checkbox","withThemeContext","withFormContext"],"sources":["../../../src/lib/components/checkbox/Checkbox.tsx"],"sourcesContent":["// Libs\r\nimport * as React from 'react';\r\n\r\n// Misc\r\nimport InputGroup from '../inputGroup/InputGroup';\r\nimport {\r\n BaseInputProps,\r\n BaseInput,\r\n BaseInputState,\r\n defaultBaseTranslations,\r\n} from '../base/input/BaseInput';\r\nvar classNames = require('classnames');\r\nimport { withFormContext } from '../form/withFormContext';\r\nimport { withThemeContext } from '../themeProvider/withThemeContext';\r\n\r\nexport interface CheckboxProps extends BaseInputProps<HTMLInputElement> {\r\n onChecked?: (e: React.ChangeEvent<HTMLInputElement>) => void;\r\n onChange?: never;\r\n type?: string;\r\n checked?: boolean;\r\n supportsIndeterminate?: boolean;\r\n}\r\n\r\nexport interface CheckboxState extends BaseInputState {\r\n checked: boolean;\r\n}\r\n\r\nexport class CheckboxRaw extends BaseInput<\r\n CheckboxProps,\r\n CheckboxState,\r\n HTMLInputElement\r\n> {\r\n public static defaultProps = Object.assign({}, BaseInput.defaultProps, {\r\n // checked: false,\r\n }) as CheckboxProps;\r\n\r\n constructor(props: CheckboxProps) {\r\n super(props, false);\r\n this.state = Object.assign(this.state, {\r\n checked: Boolean(props.checked),\r\n isValid: props.required ? props.checked : true,\r\n errors:\r\n props.required && !props.checked\r\n ? [this.getTranslations(defaultBaseTranslations).required]\r\n : [],\r\n });\r\n this.handleChecked = this.handleChecked.bind(this);\r\n this.handleKeyDown = this.handleKeyDown.bind(this);\r\n this.subscribeSelf(props);\r\n }\r\n\r\n public componentDidMount() {\r\n const finalIndeterminate = Boolean(\r\n this.props.supportsIndeterminate &&\r\n typeof this.props.checked !== 'boolean'\r\n );\r\n if (\r\n typeof this.props.checked !== 'boolean' &&\r\n this.inputRef.current &&\r\n this.inputRef.current?.indeterminate !== finalIndeterminate\r\n ) {\r\n this.inputRef.current.indeterminate = finalIndeterminate;\r\n }\r\n super.componentDidMount?.();\r\n }\r\n\r\n public componentDidUpdate(oldProps: CheckboxProps) {\r\n if (\r\n this.props.checked !== undefined &&\r\n this.props.checked !== this.state.checked\r\n ) {\r\n this.setState({ checked: this.props.checked });\r\n if (this.props.checked) {\r\n this.setValid();\r\n } else {\r\n if (this.props.required) {\r\n this.setInvalid([\r\n this.getTranslations(defaultBaseTranslations).required,\r\n ]);\r\n }\r\n }\r\n }\r\n if (oldProps.required !== this.props.required) {\r\n if (this.props.required && !this.props.checked) {\r\n this.setInvalid([\r\n this.getTranslations(defaultBaseTranslations).required,\r\n ]);\r\n } else {\r\n this.setValid();\r\n }\r\n }\r\n const finalIndeterminate = Boolean(\r\n this.props.supportsIndeterminate &&\r\n typeof this.props.checked !== 'boolean'\r\n );\r\n if (\r\n this.props.supportsIndeterminate &&\r\n this.inputRef.current?.indeterminate !== finalIndeterminate\r\n ) {\r\n this.inputRef.current.indeterminate = finalIndeterminate;\r\n }\r\n }\r\n\r\n public render() {\r\n const containerClassName = classNames([\r\n 'input__base checkbox-input',\r\n this.getValidationClass(),\r\n this.props.className,\r\n { ['checkbox-input--with-label']: Boolean(this.props.label) },\r\n { ['checkbox-input--disabled']: this.props.disabled },\r\n ]);\r\n const input = (\r\n <input\r\n {...(this.props.id && { id: this.props.id })}\r\n ref={this.inputRef}\r\n value={this.props.value || ''}\r\n type=\"checkbox\"\r\n required={this.props.required}\r\n checked={this.state.checked ?? false}\r\n onChange={this.handleChecked}\r\n onBlur={this.handleBlur}\r\n onFocus={this.handleFocus}\r\n onKeyDown={this.handleKeyDown}\r\n tabIndex={this.props.disabled ? -1 : 0}\r\n />\r\n );\r\n return (\r\n <InputGroup\r\n title={this.props.title}\r\n tooltip={this.props.tooltip}\r\n className={this.props.inputGroupClassName}\r\n >\r\n <div className={containerClassName} ref={this.containerRef}>\r\n {this.props.title && !this.props.label && input}\r\n {!this.props.title && !this.props.label && this.renderTooltip(input)}\r\n {this.renderDefaultValidation()}\r\n {this.props.label && (\r\n <label className=\"checkbox-input__label\">\r\n {input}\r\n {this.renderLabel()}\r\n </label>\r\n )}\r\n </div>\r\n </InputGroup>\r\n );\r\n }\r\n\r\n private handleChecked(e: React.ChangeEvent<HTMLInputElement>) {\r\n if (!this.props.disabled) {\r\n this.props.onChecked && this.props.onChecked(e);\r\n this.setState({ checked: !this.state.checked });\r\n if (!this.state.checked) {\r\n this.setValid();\r\n } else {\r\n if (this.props.required) {\r\n this.setInvalid([\r\n this.getTranslations(defaultBaseTranslations).required,\r\n ]);\r\n }\r\n }\r\n }\r\n }\r\n\r\n protected handleKeyDown(e: React.KeyboardEvent<HTMLInputElement>) {\r\n if (!this.props.disabled) {\r\n if (e.key === 'Enter') {\r\n this.inputRef.current?.click();\r\n }\r\n }\r\n }\r\n}\r\n\r\nexport const Checkbox = withThemeContext<\r\n CheckboxProps,\r\n InstanceType<typeof CheckboxRaw>\r\n>(withFormContext<CheckboxProps>(CheckboxRaw), 'checkbox');\r\n\r\nexport default Checkbox;\r\n"],"mappings":";;;;;;;AACA;;AAGA;;AACA;;AAOA;;AACA;;;;;;;;;;;;AAFA,IAAIA,UAAU,GAAGC,OAAO,CAAC,YAAD,CAAxB;;AAgBO,MAAMC,WAAN,SAA0BC,oBAA1B,CAIL;EAKAC,WAAW,CAACC,KAAD,EAAuB;IAChC,MAAMA,KAAN,EAAa,KAAb;IACA,KAAKC,KAAL,GAAaC,MAAM,CAACC,MAAP,CAAc,KAAKF,KAAnB,EAA0B;M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c;QAAEpB,OAAO,EAAE,CAAC,KAAKH,KAAL,CAAWG;MAAvB,CAAd;;MACA,IAAI,CAAC,KAAKH,KAAL,CAAWG,OAAhB,EAAyB;QACvB,KAAKqB,QAAL;MACD,CAFD,MAEO;QACL,IAAI,KAAKzB,KAAL,CAAWO,QAAf,EAAyB;UACvB,KAAKmB,UAAL,CAAgB,CACd,KAAKjB,eAAL,CAAqBC,kCAArB,EAA8CH,QADhC,CAAhB;QAGD;MACF;IACF;EACF;;EAESM,aAAa,CAACgC,CAAD,EAA2C;IAChE,IAAI,CAAC,KAAK7C,KAAL,CAAWgC,QAAhB,EAA0B;MACxB,IAAIa,CAAC,CAACE,GAAF,KAAU,OAAd,EAAuB;QAAA;;QACrB,+BAAK7B,QAAL,CAAcC,OAAd,kFAAuB6B,KAAvB;MACD;IACF;EACF;;AA1ID;;;;gBAJWnD,W,kBAKkBK,MAAM,CAACC,MAAP,CAAc,EAAd,EAAkBL,oBAAA,CAAUmD,YAA5B,EAA0C,CACrE;AADqE,CAA1C,C;;AA4IxB,MAAMC,QAAQ,GAAG,IAAAC,kCAAA,EAGtB,IAAAC,gCAAA,EAA+BvD,WAA/B,CAHsB,EAGuB,UAHvB,CAAjB;;eAKQqD,Q"}
|
1
|
+
{"version":3,"file":"Checkbox.js","names":["CheckboxRaw","BaseInput","constructor","props","state","Object","assign","checked","Boolean","isValid","required","errors","getTranslations","defaultBaseTranslations","handleChecked","bind","handleKeyDown","subscribeSelf","componentDidMount","finalIndeterminate","supportsIndeterminate","inputRef","current","indeterminate","componentDidUpdate","oldProps","undefined","setState","setValid","setInvalid","render","containerClassName","classNames","getValidationClass","className","label","disabled","input","id","value","handleBlur","handleFocus","title","tooltip","inputGroupClassName","containerRef","renderTooltip","renderDefaultValidation","renderLabel","e","onChecked","key","click","defaultProps","Checkbox","withThemeContext","withFormContext"],"sources":["../../../src/lib/components/checkbox/Checkbox.tsx"],"sourcesContent":["// Libs\r\nimport * as React from 'react';\r\n\r\n// Misc\r\nimport InputGroup from '../inputGroup/InputGroup';\r\nimport {\r\n BaseInputProps,\r\n BaseInput,\r\n BaseInputState,\r\n defaultBaseTranslations,\r\n} from '../base/input/BaseInput';\r\nimport classNames from 'classnames';\r\nimport { withFormContext } from '../form/withFormContext';\r\nimport { withThemeContext } from '../themeProvider/withThemeContext';\r\n\r\nexport interface CheckboxProps extends BaseInputProps<HTMLInputElement> {\r\n onChecked?: (e: React.ChangeEvent<HTMLInputElement>) => void;\r\n onChange?: never;\r\n type?: string;\r\n checked?: boolean;\r\n supportsIndeterminate?: boolean;\r\n}\r\n\r\nexport interface CheckboxState extends BaseInputState {\r\n checked: boolean;\r\n}\r\n\r\nexport class CheckboxRaw extends BaseInput<\r\n CheckboxProps,\r\n CheckboxState,\r\n HTMLInputElement\r\n> {\r\n public static defaultProps = Object.assign({}, BaseInput.defaultProps, {\r\n // checked: false,\r\n }) as CheckboxProps;\r\n\r\n constructor(props: CheckboxProps) {\r\n super(props, false);\r\n this.state = Object.assign(this.state, {\r\n checked: Boolean(props.checked),\r\n isValid: props.required ? props.checked : true,\r\n errors:\r\n props.required && !props.checked\r\n ? [this.getTranslations(defaultBaseTranslations).required]\r\n : [],\r\n });\r\n this.handleChecked = this.handleChecked.bind(this);\r\n this.handleKeyDown = this.handleKeyDown.bind(this);\r\n this.subscribeSelf(props);\r\n }\r\n\r\n public componentDidMount() {\r\n const finalIndeterminate = Boolean(\r\n this.props.supportsIndeterminate &&\r\n typeof this.props.checked !== 'boolean'\r\n );\r\n if (\r\n typeof this.props.checked !== 'boolean' &&\r\n this.inputRef.current &&\r\n this.inputRef.current?.indeterminate !== finalIndeterminate\r\n ) {\r\n this.inputRef.current.indeterminate = finalIndeterminate;\r\n }\r\n super.componentDidMount?.();\r\n }\r\n\r\n public componentDidUpdate(oldProps: CheckboxProps) {\r\n if (\r\n this.props.checked !== undefined &&\r\n this.props.checked !== this.state.checked\r\n ) {\r\n this.setState({ checked: this.props.checked });\r\n if (this.props.checked) {\r\n this.setValid();\r\n } else {\r\n if (this.props.required) {\r\n this.setInvalid([\r\n this.getTranslations(defaultBaseTranslations).required,\r\n ]);\r\n }\r\n }\r\n }\r\n if (oldProps.required !== this.props.required) {\r\n if (this.props.required && !this.props.checked) {\r\n this.setInvalid([\r\n this.getTranslations(defaultBaseTranslations).required,\r\n ]);\r\n } else {\r\n this.setValid();\r\n }\r\n }\r\n const finalIndeterminate = Boolean(\r\n this.props.supportsIndeterminate &&\r\n typeof this.props.checked !== 'boolean'\r\n );\r\n if (\r\n this.props.supportsIndeterminate &&\r\n this.inputRef.current?.indeterminate !== finalIndeterminate\r\n ) {\r\n this.inputRef.current.indeterminate = finalIndeterminate;\r\n }\r\n }\r\n\r\n public render() {\r\n const containerClassName = classNames([\r\n 'input__base checkbox-input',\r\n this.getValidationClass(),\r\n this.props.className,\r\n { ['checkbox-input--with-label']: Boolean(this.props.label) },\r\n { ['checkbox-input--disabled']: this.props.disabled },\r\n ]);\r\n const input = (\r\n <input\r\n {...(this.props.id && { id: this.props.id })}\r\n ref={this.inputRef}\r\n value={this.props.value || ''}\r\n type=\"checkbox\"\r\n required={this.props.required}\r\n checked={this.state.checked ?? false}\r\n onChange={this.handleChecked}\r\n onBlur={this.handleBlur}\r\n onFocus={this.handleFocus}\r\n onKeyDown={this.handleKeyDown}\r\n tabIndex={this.props.disabled ? -1 : 0}\r\n />\r\n );\r\n return (\r\n <InputGroup\r\n title={this.props.title}\r\n tooltip={this.props.tooltip}\r\n className={this.props.inputGroupClassName}\r\n >\r\n <div className={containerClassName} ref={this.containerRef}>\r\n {this.props.title && !this.props.label && input}\r\n {!this.props.title && !this.props.label && this.renderTooltip(input)}\r\n {this.renderDefaultValidation()}\r\n {this.props.label && (\r\n <label className=\"checkbox-input__label\">\r\n {input}\r\n {this.renderLabel()}\r\n </label>\r\n )}\r\n </div>\r\n </InputGroup>\r\n );\r\n }\r\n\r\n private handleChecked(e: React.ChangeEvent<HTMLInputElement>) {\r\n if (!this.props.disabled) {\r\n this.props.onChecked && this.props.onChecked(e);\r\n this.setState({ checked: !this.state.checked });\r\n if (!this.state.checked) {\r\n this.setValid();\r\n } else {\r\n if (this.props.required) {\r\n this.setInvalid([\r\n this.getTranslations(defaultBaseTranslations).required,\r\n ]);\r\n }\r\n }\r\n }\r\n }\r\n\r\n protected handleKeyDown(e: React.KeyboardEvent<HTMLInputElement>) {\r\n if (!this.props.disabled) {\r\n if (e.key === 'Enter') {\r\n this.inputRef.current?.click();\r\n }\r\n }\r\n }\r\n}\r\n\r\nexport const Checkbox = withThemeContext<\r\n CheckboxProps,\r\n InstanceType<typeof CheckboxRaw>\r\n>(withFormContext<CheckboxProps>(CheckboxRaw), 'checkbox');\r\n\r\nexport default Checkbox;\r\n"],"mappings":";;;;;;;AACA;;AAGA;;AACA;;AAMA;;AACA;;AACA;;;;;;;;;;;;AAcO,MAAMA,WAAN,SAA0BC,oBAA1B,CAIL;EAKAC,WAAW,CAACC,KAAD,EAAuB;IAChC,MAAMA,KAAN,EAAa,KAAb;IACA,KAAKC,KAAL,GAAaC,MAAM,CAACC,MAAP,CAAc,KAAKF,KAAnB,EAA0B;MACrCG,OAAO,EAAEC,OAAO,CAACL,KAAK,CAACI,OAAP,CADqB;MAErCE,OAAO,EAAEN,KAAK,CAACO,QAAN,GAAiBP,KAAK,CAACI,OAAvB,GAAiC,IAFL;MAGrCI,MAAM,EACJR,KAAK,CAACO,QAAN,IAAkB,CAACP,KAAK,CAACI,OAAzB,GACI,CAAC,KAAKK,eAAL,CAAqBC,kCAArB,EAA8CH,QAA/C,CADJ,GAEI;IAN+B,CAA1B,CAAb;IAQA,KAAKI,aAAL,GAAqB,KAAKA,aAAL,CAAmBC,IAAnB,CAAwB,IAAxB,CAArB;IACA,KAAKC,aAAL,GAAqB,KAAKA,aAAL,CAAmBD,IAAnB,CAAwB,IAAxB,CAArB;IACA,KAAKE,aAAL,CAAmBd,KAAnB;EACD;;EAEMe,iBAAiB,GAAG;IAAA;;IACzB,MAAMC,kBAAkB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;gBAJWpD,W,kBAKkBK,MAAM,CAACC,MAAP,CAAc,EAAd,EAAkBL,oBAAA,CAAUoD,YAA5B,EAA0C,CACrE;AADqE,CAA1C,C;;AA4IxB,MAAMC,QAAQ,GAAG,IAAAC,kCAAA,EAGtB,IAAAC,gCAAA,EAA+BxD,WAA/B,CAHsB,EAGuB,UAHvB,CAAjB;;eAKQsD,Q"}
|
@@ -7,12 +7,16 @@ exports.default = exports.DynamicSubmitRaw = exports.DynamicSubmitMode = exports
|
|
7
7
|
|
8
8
|
var React = _interopRequireWildcard(require("react"));
|
9
9
|
|
10
|
+
var _classnames = _interopRequireDefault(require("classnames"));
|
11
|
+
|
10
12
|
var _withFormContext = require("../form/withFormContext");
|
11
13
|
|
12
14
|
var _Submit = require("./../submit/Submit");
|
13
15
|
|
14
16
|
var _withThemeContext = require("../themeProvider/withThemeContext");
|
15
17
|
|
18
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
19
|
+
|
16
20
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
17
21
|
|
18
22
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
@@ -21,8 +25,6 @@ function _extends() { _extends = Object.assign ? Object.assign.bind() : function
|
|
21
25
|
|
22
26
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
23
27
|
|
24
|
-
var classNames = require('classnames');
|
25
|
-
|
26
28
|
// Misc
|
27
29
|
let DynamicSubmitMode;
|
28
30
|
exports.DynamicSubmitMode = DynamicSubmitMode;
|
@@ -48,7 +50,7 @@ class DynamicSubmitRaw extends React.PureComponent {
|
|
48
50
|
}
|
49
51
|
|
50
52
|
render() {
|
51
|
-
const buttonClassName =
|
53
|
+
const buttonClassName = (0, _classnames.default)(this.props.className, this.renderClassName());
|
52
54
|
return /*#__PURE__*/React.createElement(_Submit.SubmitRaw, _extends({}, this.props, {
|
53
55
|
className: buttonClassName,
|
54
56
|
onClick: this.handleClick
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"DynamicSubmit.js","names":["
|
1
|
+
{"version":3,"file":"DynamicSubmit.js","names":["DynamicSubmitMode","DynamicSubmitRaw","React","PureComponent","constructor","props","state","buttonState","Normal","handleClick","bind","submitting","error","success","reset","render","buttonClassName","classNames","className","renderClassName","renderChildren","e","preventDefault","submitDisablesInputs","formContext","disableComponents","onClick","setState","Submitting","Error","Success","resetEnablesInputs","enableComponents","errorChildren","children","submittingChildren","successChildren","errorClassName","submittingClassName","successClassName","normalClassName","Object","assign","validateForm","DynamicSubmit","withThemeContext","withFormContext"],"sources":["../../../src/lib/components/dynamicSubmit/DynamicSubmit.tsx"],"sourcesContent":["// Libs\r\nimport * as React from 'react';\r\nimport classNames from 'classnames';\r\nimport { withFormContext } from '../form/withFormContext';\r\nimport { FormContextProps } from '../form/FormContext';\r\nimport { SubmitProps } from '../submit';\r\nimport { Omit } from '../utils/Typescript';\r\nimport { SubmitRaw } from './../submit/Submit';\r\nimport { withThemeContext } from '../themeProvider/withThemeContext';\r\n\r\n// Misc\r\n\r\nexport enum DynamicSubmitMode {\r\n Normal,\r\n Submitting,\r\n Error,\r\n Success,\r\n}\r\n\r\nexport type DynamicSubmitProps = Omit<SubmitProps, 'onClick'> & {\r\n onClick?: (\r\n e: React.MouseEvent<HTMLButtonElement>,\r\n submitting?: () => void,\r\n error?: () => void,\r\n success?: () => void,\r\n reset?: () => void\r\n ) => void;\r\n submittingChildren?: JSX.Element | string;\r\n errorChildren?: JSX.Element | string;\r\n successChildren?: JSX.Element | string;\r\n\r\n submittingClassName?: string;\r\n errorClassName?: string;\r\n successClassName?: string;\r\n normalClassName?: string;\r\n\r\n submitDisablesInputs?: boolean;\r\n resetEnablesInputs?: boolean;\r\n} & FormContextProps;\r\n\r\nexport interface DynamicSubmitState {\r\n buttonState: DynamicSubmitMode;\r\n}\r\n\r\nexport class DynamicSubmitRaw extends React.PureComponent<\r\n DynamicSubmitProps,\r\n DynamicSubmitState\r\n> {\r\n public static defaultProps = Object.assign(\r\n {},\r\n { validateForm: true, submitDisablesInputs: true, resetEnablesInputs: true }\r\n );\r\n\r\n constructor(props: DynamicSubmitProps) {\r\n super(props);\r\n this.state = {\r\n buttonState: DynamicSubmitMode.Normal,\r\n };\r\n this.handleClick = this.handleClick.bind(this);\r\n this.submitting = this.submitting.bind(this);\r\n this.error = this.error.bind(this);\r\n this.success = this.success.bind(this);\r\n this.reset = this.reset.bind(this);\r\n }\r\n\r\n public render() {\r\n const buttonClassName = classNames(\r\n this.props.className,\r\n this.renderClassName()\r\n );\r\n return (\r\n <SubmitRaw\r\n {...this.props}\r\n className={buttonClassName}\r\n onClick={this.handleClick}\r\n >\r\n {this.renderChildren()}\r\n </SubmitRaw>\r\n );\r\n }\r\n\r\n private handleClick(e: React.MouseEvent<HTMLButtonElement>) {\r\n e.preventDefault();\r\n this.props.submitDisablesInputs &&\r\n this.props.formContext.disableComponents();\r\n this.props.onClick &&\r\n this.props.onClick(\r\n e,\r\n this.submitting,\r\n this.error,\r\n this.success,\r\n this.reset\r\n );\r\n }\r\n\r\n private submitting() {\r\n this.setState({ buttonState: DynamicSubmitMode.Submitting });\r\n }\r\n\r\n private error() {\r\n this.setState({ buttonState: DynamicSubmitMode.Error });\r\n }\r\n\r\n private success() {\r\n this.setState({ buttonState: DynamicSubmitMode.Success });\r\n }\r\n\r\n private reset() {\r\n this.props.resetEnablesInputs && this.props.formContext.enableComponents();\r\n this.setState({ buttonState: DynamicSubmitMode.Normal });\r\n }\r\n\r\n private renderChildren() {\r\n switch (this.state.buttonState) {\r\n case DynamicSubmitMode.Error:\r\n return this.props.errorChildren\r\n ? this.props.errorChildren\r\n : this.props.children;\r\n case DynamicSubmitMode.Submitting:\r\n return this.props.submittingChildren\r\n ? this.props.submittingChildren\r\n : this.props.children;\r\n case DynamicSubmitMode.Success:\r\n return this.props.successChildren\r\n ? this.props.successChildren\r\n : this.props.children;\r\n default:\r\n return this.props.children;\r\n }\r\n }\r\n\r\n private renderClassName() {\r\n switch (this.state.buttonState) {\r\n case DynamicSubmitMode.Error:\r\n return this.props.errorClassName ? this.props.errorClassName : '';\r\n case DynamicSubmitMode.Submitting:\r\n return this.props.submittingClassName\r\n ? this.props.submittingClassName\r\n : '';\r\n case DynamicSubmitMode.Success:\r\n return this.props.successClassName ? this.props.successClassName : '';\r\n default:\r\n return this.props.normalClassName ? this.props.normalClassName : '';\r\n }\r\n }\r\n}\r\n\r\nexport const DynamicSubmit = withThemeContext<\r\n DynamicSubmitProps,\r\n InstanceType<typeof DynamicSubmitRaw>\r\n>(withFormContext<DynamicSubmitProps>(DynamicSubmitRaw), 'dynamicSubmit');\r\n\r\nexport default DynamicSubmit;\r\n"],"mappings":";;;;;;;AACA;;AACA;;AACA;;AAIA;;AACA;;;;;;;;;;;;AAEA;IAEYA,iB;;;WAAAA,iB;EAAAA,iB,CAAAA,iB;EAAAA,iB,CAAAA,iB;EAAAA,iB,CAAAA,iB;EAAAA,iB,CAAAA,iB;GAAAA,iB,iCAAAA,iB;;AAgCL,MAAMC,gBA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AAWiC,mBADR,GAEH,EAFJ;;MAGF,KAAKtC,iBAAiB,CAAC8B,OAAvB;QACE,OAAO,KAAKzB,KAAL,CAAWkC,gBAAX,GAA8B,KAAKlC,KAAL,CAAWkC,gBAAzC,GAA4D,EAAnE;;MACF;QACE,OAAO,KAAKlC,KAAL,CAAWmC,eAAX,GAA6B,KAAKnC,KAAL,CAAWmC,eAAxC,GAA0D,EAAjE;IAVJ;EAYD;;AAjGD;;;;gBAHWvC,gB,kBAIkBwC,MAAM,CAACC,MAAP,CAC3B,EAD2B,EAE3B;EAAEC,YAAY,EAAE,IAAhB;EAAsBpB,oBAAoB,EAAE,IAA5C;EAAkDQ,kBAAkB,EAAE;AAAtE,CAF2B,C;;AAmGxB,MAAMa,aAAa,GAAG,IAAAC,kCAAA,EAG3B,IAAAC,gCAAA,EAAoC7C,gBAApC,CAH2B,EAG4B,eAH5B,CAAtB;;eAKQ2C,a"}
|
@@ -13,6 +13,8 @@ var _withFormContext = require("./withFormContext");
|
|
13
13
|
|
14
14
|
var _Button = require("./../button/Button");
|
15
15
|
|
16
|
+
var _classnames = _interopRequireDefault(require("classnames"));
|
17
|
+
|
16
18
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
17
19
|
|
18
20
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
@@ -21,8 +23,6 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
|
|
21
23
|
|
22
24
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
23
25
|
|
24
|
-
var classNames = require('classnames');
|
25
|
-
|
26
26
|
var ArrowIcon = function ArrowIcon(props) {
|
27
27
|
return /*#__PURE__*/React.createElement("svg", props, /*#__PURE__*/React.createElement("path", {
|
28
28
|
d: "M12 8c-2.21 0-4 1.79-4 4s1.79 4 4 4 4-1.79 4-4-1.79-4-4-4zm8.94 3A8.994 8.994 0 0 0 13 3.06V1h-2v2.06A8.994 8.994 0 0 0 3.06 11H1v2h2.06A8.994 8.994 0 0 0 11 20.94V23h2v-2.06A8.994 8.994 0 0 0 20.94 13H23v-2h-2.06zM12 19c-3.87 0-7-3.13-7-7s3.13-7 7-7 7 3.13 7 7-3.13 7-7 7z"
|
@@ -82,9 +82,9 @@ class FormValidationSummaryRaw extends React.PureComponent {
|
|
82
82
|
|
83
83
|
return !component.validation.isValid;
|
84
84
|
}) : [];
|
85
|
-
const containerClassName =
|
86
|
-
const headerClassName =
|
87
|
-
const footerClassName =
|
85
|
+
const containerClassName = (0, _classnames.default)(this.props.containerClassName);
|
86
|
+
const headerClassName = (0, _classnames.default)(this.props.headerClassName);
|
87
|
+
const footerClassName = (0, _classnames.default)(this.props.footerClassName);
|
88
88
|
return componentsWithErrors.length > 0 && /*#__PURE__*/React.createElement("div", {
|
89
89
|
className: containerClassName
|
90
90
|
}, this.props.title && /*#__PURE__*/React.createElement("div", {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"FormValidationSummary.js","names":["
|
1
|
+
{"version":3,"file":"FormValidationSummary.js","names":["ArrowIcon","DefaultComponent","props","componentsWithErrors","map","component","index","validation","name","errors","err","errIndex","flex","componentApi","focus","scrollTo","FormValidationSummaryRaw","React","PureComponent","guid","render","formContext","Object","keys","components","key","filter","isValid","console","warn","containerClassName","classNames","headerClassName","footerClassName","length","title","footer","Component","FormValidationSummary","withFormContext"],"sources":["../../../src/lib/components/form/FormValidationSummary.tsx"],"sourcesContent":["import * as React from 'react';\r\nimport guid from '../utils/Guid';\r\nimport { withFormContext } from './withFormContext';\r\nimport { FormContextProps, FormComponentContextState } from './FormContext';\r\nimport { Button } from './../button/Button';\r\nimport classNames from 'classnames';\r\n\r\nimport * as ArrowIcon from 'material-design-icons/maps/svg/production/ic_my_location_24px.svg';\r\n\r\nexport interface FormValidationSummaryComponentProps {\r\n componentsWithErrors: FormComponentContextState[];\r\n}\r\n\r\nexport type FormValidationSummaryProps = {\r\n containerClassName?: string;\r\n headerClassName?: string;\r\n footerClassName?: string;\r\n title?: string | JSX.Element;\r\n footer?: string | JSX.Element;\r\n Component?:\r\n | React.ComponentType<FormValidationSummaryComponentProps>\r\n | React.StatelessComponent<FormValidationSummaryComponentProps>;\r\n} & FormContextProps;\r\n\r\nexport interface FormValidationSummaryState {}\r\n\r\nexport const DefaultComponent: React.FC<FormValidationSummaryComponentProps> = props => (\r\n <React.Fragment>\r\n {props.componentsWithErrors.map((component, index) => {\r\n return (\r\n <div key={index} className=\"formValidationSummary__item\">\r\n <div className=\"formValidationSummary__item__header\">\r\n {component.validation.name ? component.validation.name : 'unknown'}\r\n </div>\r\n <div className=\"formValidationSummary__item__errors\">\r\n {component.validation.errors &&\r\n component.validation.errors.map((err, errIndex) => (\r\n <span\r\n className=\"formValidationSummary__item__error\"\r\n key={errIndex}\r\n >\r\n {err}\r\n </span>\r\n ))}\r\n </div>\r\n <div style={{ flex: 'auto' }} />\r\n {component.componentApi &&\r\n component.componentApi.focus &&\r\n component.componentApi.scrollTo && (\r\n <Button\r\n icon={true}\r\n className=\"formValidationSummary__item__locate-button\"\r\n circular={true}\r\n type=\"error\"\r\n small={true}\r\n blank={true}\r\n onClick={() => {\r\n component.componentApi.scrollTo();\r\n component.componentApi.focus();\r\n }}\r\n >\r\n <ArrowIcon />\r\n </Button>\r\n )}\r\n </div>\r\n );\r\n })}\r\n </React.Fragment>\r\n);\r\n\r\nexport class FormValidationSummaryRaw extends React.PureComponent<\r\n FormValidationSummaryProps,\r\n FormValidationSummaryState\r\n> {\r\n public static defaultProps = {\r\n title: 'Hang on',\r\n footer: '... needs fixing',\r\n Component: DefaultComponent,\r\n containerClassName: 'formValidationSummary',\r\n headerClassName: 'formValidationSummary__header',\r\n footerClassName: 'formValidationSummary__footer',\r\n };\r\n\r\n public componentId = guid();\r\n\r\n public render() {\r\n const componentsWithErrors = this.props.formContext\r\n ? Object.keys(this.props.formContext.components)\r\n .map(key => this.props.formContext.components[key])\r\n .filter(component => {\r\n if (!component.validation.isValid && !component.validation.name) {\r\n console.warn(\r\n component,\r\n 'Has validation error. FormValidationSummary is present but the component has no validation name'\r\n );\r\n }\r\n return !component.validation.isValid;\r\n })\r\n : [];\r\n const containerClassName = classNames(this.props.containerClassName);\r\n const headerClassName = classNames(this.props.headerClassName);\r\n const footerClassName = classNames(this.props.footerClassName);\r\n return (\r\n componentsWithErrors.length > 0 && (\r\n <div className={containerClassName}>\r\n {this.props.title && (\r\n <div className={headerClassName}>{this.props.title}</div>\r\n )}\r\n <this.props.Component componentsWithErrors={componentsWithErrors} />\r\n {this.props.footer && (\r\n <div className={footerClassName}>{this.props.footer}</div>\r\n )}\r\n </div>\r\n )\r\n );\r\n }\r\n}\r\n\r\nexport const FormValidationSummary = withFormContext<\r\n FormValidationSummaryProps\r\n>(FormValidationSummaryRaw);\r\n"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AAEA;;AACA;;;;;;;;;;IAEYA,S,YAAAA,S;;;;;;AAAAA,S;;;;;;;AAmBL,MAAMC,gBAA+D,GAAGC,KAAK,iBAClF,oBAAC,KAAD,CAAO,QAAP,QACGA,KAAK,CAACC,oBAAN,CAA2BC,GAA3B,CAA+B,CAACC,SAAD,EAAYC,KAAZ,KAAsB;EACpD,oBACE;IAAK,GAAG,EAAEA,KAAV;IAAiB,SAAS,EAAC;EAA3B,gBACE;IAAK,SAAS,EAAC;EAAf,GACGD,SAAS,CAACE,UAAV,CAAqBC,IAArB,GAA4BH,SAAS,CAACE,UAAV,CAAqBC,IAAjD,GAAwD,SAD3D,CADF,eAIE;IAAK,SAAS,EAAC;EAAf,GACGH,SAAS,CAACE,UAAV,CAAqBE,MAArB,IACCJ,SAAS,CAACE,UAAV,CAAqBE,M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SAAS,CAACE,UAAV,CAAqBoB,OAA7B;IACD,CAVH,CADyB,GAYzB,EAZJ;IAaA,MAAMG,kBAAkB,GAAG,IAAAC,mBAAA,EAAW,KAAK7B,KAAL,CAAW4B,kBAAtB,CAA3B;IACA,MAAME,eAAe,GAAG,IAAAD,mBAAA,EAAW,KAAK7B,KAAL,CAAW8B,eAAtB,CAAxB;IACA,MAAMC,eAAe,GAAG,IAAAF,mBAAA,EAAW,KAAK7B,KAAL,CAAW+B,eAAtB,CAAxB;IACA,OACE9B,oBAAoB,CAAC+B,MAArB,GAA8B,CAA9B,iBACE;MAAK,SAAS,EAAEJ;IAAhB,GACG,KAAK5B,KAAL,CAAWiC,KAAX,iBACC;MAAK,SAAS,EAAEH;IAAhB,GAAkC,KAAK9B,KAAL,CAAWiC,KAA7C,CAFJ,eAIE,yBAAM,KAAN,CAAY,SAAZ;MAAsB,oBAAoB,EAAEhC;IAA5C,EAJF,EAKG,KAAKD,KAAL,CAAWkC,MAAX,iBACC;MAAK,SAAS,EAAEH;IAAhB,GAAkC,KAAK/B,KAAL,CAAWkC,MAA7C,CANJ,CAFJ;EAaD;;AA1CD;;;;gBAHWpB,wB,kBAIkB;EAC3BmB,KAAK,EAAE,SADoB;EAE3BC,MAAM,EAAE,kBAFmB;EAG3BC,SAAS,EAAEpC,gBAHgB;EAI3B6B,kBAAkB,EAAE,uBAJO;EAK3BE,eAAe,EAAE,+BALU;EAM3BC,eAAe,EAAE;AANU,C;;AA4CxB,MAAMK,qBAAqB,GAAG,IAAAC,gCAAA,EAEnCvB,wBAFmC,CAA9B"}
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import * as React from 'react';
|
2
2
|
import { ButtonProps } from '../button/Button';
|
3
3
|
import { OmitInputHeaderContext, InputHeaderContextProps, InputHeaderContextState } from '../inputHeader/InputHeaderContext';
|
4
|
-
import { TippyProps } from '@tippy.js/react';
|
4
|
+
import type { TippyProps } from '@tippy.js/react';
|
5
5
|
import { ThemeContextProps } from '../themeProvider/ThemeContext';
|
6
6
|
export declare type InputHeaderRawProps = React.PropsWithChildren<{
|
7
7
|
onExpanded?: () => void;
|
@@ -7,6 +7,8 @@ exports.default = exports.InputHeaderRaw = exports.InputHeader = void 0;
|
|
7
7
|
|
8
8
|
var React = _interopRequireWildcard(require("react"));
|
9
9
|
|
10
|
+
var _classnames = _interopRequireDefault(require("classnames"));
|
11
|
+
|
10
12
|
var _Button = require("../button/Button");
|
11
13
|
|
12
14
|
var _Guid = _interopRequireDefault(require("../utils/Guid"));
|
@@ -33,9 +35,7 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
33
35
|
|
34
36
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
35
37
|
|
36
|
-
|
37
|
-
|
38
|
-
|
38
|
+
// Misc
|
39
39
|
var MoreIcon = function MoreIcon(props) {
|
40
40
|
return /*#__PURE__*/React.createElement("svg", props, /*#__PURE__*/React.createElement("path", {
|
41
41
|
d: "M12 8c1.1 0 2-.9 2-2s-.9-2-2-2-2 .9-2 2 .9 2 2 2zm0 2c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2zm0 6c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2z"
|
@@ -187,7 +187,7 @@ class InputHeaderRaw extends React.PureComponent {
|
|
187
187
|
return /*#__PURE__*/React.createElement("div", {
|
188
188
|
className: `input__header ` + (this.props.className ? this.props.className : '') + ' ' + this.getTypeClass()
|
189
189
|
}, /*#__PURE__*/React.createElement("div", {
|
190
|
-
className:
|
190
|
+
className: (0, _classnames.default)('input__header__top', {
|
191
191
|
'input__header__top--tall': this.props.showExpandAll
|
192
192
|
}, {
|
193
193
|
'input__header__top--no-bg': this.props.noBg
|