@propellerads/time-picker 1.2.0 → 1.3.0
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/dist/time-picker.cjs.development.js +6 -3
- package/dist/time-picker.cjs.development.js.map +1 -1
- package/dist/time-picker.cjs.production.min.js +1 -1
- package/dist/time-picker.cjs.production.min.js.map +1 -1
- package/dist/time-picker.esm.js +6 -3
- package/dist/time-picker.esm.js.map +1 -1
- package/package.json +3 -4
- package/src/index.tsx +6 -8
- package/src/style.tsx +16 -16
- package/src/types.ts +11 -11
- package/CHANGELOG.md +0 -7
|
@@ -21,9 +21,9 @@ function _taggedTemplateLiteralLoose(strings, raw) {
|
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
var _templateObject, _templateObject2, _templateObject3;
|
|
24
|
-
var StyledTimeContainer = /*#__PURE__*/styled.div(_templateObject || (_templateObject = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n
|
|
25
|
-
var StyledInputTime = /*#__PURE__*/themeAnnotation.themeAnnotation( /*#__PURE__*/styled.input(_templateObject2 || (_templateObject2 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n border: 1px solid ", ";\n border-radius: 8px;\n padding: 0 7px;\n font-size: 14px;\n height: 36px;\n
|
|
26
|
-
var StyledTimePickerHelper = /*#__PURE__*/styled.div(_templateObject3 || (_templateObject3 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n
|
|
24
|
+
var StyledTimeContainer = /*#__PURE__*/styled.div(_templateObject || (_templateObject = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n display: flex;\n position: relative;\n width: 82px;\n"])));
|
|
25
|
+
var StyledInputTime = /*#__PURE__*/themeAnnotation.themeAnnotation( /*#__PURE__*/styled.input(_templateObject2 || (_templateObject2 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n border: 1px solid ", ";\n border-radius: 8px;\n padding: 0 7px;\n font-size: 14px;\n height: 36px;\n\n &[disabled] {\n background-color: ", ";\n }\n\n &[data-has-errors='true'] {\n border: 1px solid ", " !important;\n color: ", ";\n\n &::-webkit-calendar-picker-indicator {\n filter: invert(22%) sepia(63%) saturate(7197%) hue-rotate(353deg) brightness(106%) contrast(87%);\n }\n }\n "])), stylevariables.gray80, stylevariables.gray95, stylevariables.errorColor, stylevariables.errorColor), themeAnnotation.Input);
|
|
26
|
+
var StyledTimePickerHelper = /*#__PURE__*/styled.div(_templateObject3 || (_templateObject3 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n position: absolute;\n right: 1px;\n top: calc(50% - ", "px);\n"])), stylevariables.spacing * 2.5);
|
|
27
27
|
|
|
28
28
|
var DEFAULT_MIN_TIME = '00:00';
|
|
29
29
|
var DEFAULT_MAX_TIME = '23:59';
|
|
@@ -50,10 +50,13 @@ var TimePicker = function TimePicker(_ref) {
|
|
|
50
50
|
onChange(correctTime);
|
|
51
51
|
};
|
|
52
52
|
|
|
53
|
+
var inputTimeElementId = elementId + "-input-time";
|
|
53
54
|
return React.createElement(React.Fragment, null, label && React.createElement(Label, {
|
|
55
|
+
"for": inputTimeElementId,
|
|
54
56
|
label: label,
|
|
55
57
|
required: isRequired
|
|
56
58
|
}), React.createElement(StyledTimeContainer, null, React.createElement(StyledInputTime, {
|
|
59
|
+
id: inputTimeElementId,
|
|
57
60
|
"data-has-errors": Boolean(errors === null || errors === void 0 ? void 0 : errors.length),
|
|
58
61
|
required: isRequired,
|
|
59
62
|
disabled: isReadonly,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"time-picker.cjs.development.js","sources":["../src/style.tsx","../src/index.tsx"],"sourcesContent":["import styled, {StyledComponent} from 'styled-components';\nimport {
|
|
1
|
+
{"version":3,"file":"time-picker.cjs.development.js","sources":["../src/style.tsx","../src/index.tsx"],"sourcesContent":["import styled, {StyledComponent} from 'styled-components';\nimport {spacing, errorColor, gray80, gray95} from '@propellerads/stylevariables';\nimport {Input, themeAnnotation} from '@propellerads/theme-annotation';\n\nexport const StyledTimeContainer = styled.div`\n display: flex;\n position: relative;\n width: 82px;\n`;\n\nexport const StyledInputTime = themeAnnotation(\n styled.input`\n border: 1px solid ${gray80};\n border-radius: 8px;\n padding: 0 7px;\n font-size: 14px;\n height: 36px;\n\n &[disabled] {\n background-color: ${gray95};\n }\n\n &[data-has-errors='true'] {\n border: 1px solid ${errorColor} !important;\n color: ${errorColor};\n\n &::-webkit-calendar-picker-indicator {\n filter: invert(22%) sepia(63%) saturate(7197%) hue-rotate(353deg) brightness(106%) contrast(87%);\n }\n }\n `,\n Input,\n) as StyledComponent<'input', any>;\n\nexport const StyledTimePickerHelper = styled.div`\n position: absolute;\n right: 1px;\n top: calc(50% - ${spacing * 2.5}px);\n`;\n","import React, {ChangeEvent, FunctionComponent} from 'react';\n\nimport Label from '@propellerads/label';\nimport ErrorLabel from '@propellerads/error-label';\n\nimport {StyledTimeContainer, StyledInputTime, StyledTimePickerHelper} from './style';\nimport {TimePickerProps} from './types';\n\nconst DEFAULT_MIN_TIME = '00:00';\nconst DEFAULT_MAX_TIME = '23:59';\n\nconst TimePicker: FunctionComponent<TimePickerProps> = ({\n elementId,\n onChange,\n errors,\n value,\n minTime,\n maxTime,\n label,\n isRequired,\n isReadonly,\n showErrorLabel,\n}: TimePickerProps) => {\n const onChangeTime = (event: ChangeEvent<HTMLInputElement>) => {\n onChange(event.target.value);\n };\n\n const onChangeCorrectTime = (event: ChangeEvent<HTMLInputElement>) => {\n const timesArray = [minTime ?? DEFAULT_MIN_TIME, maxTime ?? DEFAULT_MAX_TIME, event.target.value];\n const correctTime = timesArray.sort()[1];\n\n onChange(correctTime);\n };\n\n const inputTimeElementId = `${elementId}-input-time`;\n\n return (\n <>\n {label && <Label for={inputTimeElementId} label={label} required={isRequired} />}\n <StyledTimeContainer>\n <StyledInputTime\n id={inputTimeElementId}\n data-has-errors={Boolean(errors?.length)}\n required={isRequired}\n disabled={isReadonly}\n onChange={onChangeTime}\n onBlur={onChangeCorrectTime}\n type=\"time\"\n value={value}\n />\n {showErrorLabel && (\n <StyledTimePickerHelper>\n <ErrorLabel elementId={elementId} errors={errors?.slice()} />\n </StyledTimePickerHelper>\n )}\n </StyledTimeContainer>\n </>\n );\n};\n\nexport default TimePicker;\n"],"names":["StyledTimeContainer","styled","div","StyledInputTime","themeAnnotation","input","gray80","gray95","errorColor","Input","StyledTimePickerHelper","spacing","DEFAULT_MIN_TIME","DEFAULT_MAX_TIME","TimePicker","elementId","onChange","errors","value","minTime","maxTime","label","isRequired","isReadonly","showErrorLabel","onChangeTime","event","target","onChangeCorrectTime","timesArray","correctTime","sort","inputTimeElementId","React","Label","required","id","Boolean","length","disabled","onBlur","type","ErrorLabel","slice"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAIO,IAAMA,mBAAmB,gBAAGC,MAAM,CAACC,GAAV,kJAAzB;AAMA,IAAMC,eAAe,gBAAGC,+BAAe,eAC5CH,MAAM,CAACI,KADqC,yhBAEtBC,qBAFsB,EASpBC,qBAToB,EAapBC,yBAboB,EAc/BA,yBAd+B,GAqB5CC,qBArB4C,CAAvC;AAwBA,IAAMC,sBAAsB,gBAAGT,MAAM,CAACC,GAAV,8JAGfS,sBAAO,GAAG,GAHK,CAA5B;;AC1BP,IAAMC,gBAAgB,GAAG,OAAzB;AACA,IAAMC,gBAAgB,GAAG,OAAzB;;AAEA,IAAMC,UAAU,GAAuC,SAAjDA,UAAiD;MACrDC,iBAAAA;MACAC,gBAAAA;MACAC,cAAAA;MACAC,aAAAA;MACAC,eAAAA;MACAC,eAAAA;MACAC,aAAAA;MACAC,kBAAAA;MACAC,kBAAAA;MACAC,sBAAAA;;EAEA,IAAMC,YAAY,GAAG,SAAfA,YAAe,CAACC,KAAD;IACnBV,QAAQ,CAACU,KAAK,CAACC,MAAN,CAAaT,KAAd,CAAR;GADF;;EAIA,IAAMU,mBAAmB,GAAG,SAAtBA,mBAAsB,CAACF,KAAD;IAC1B,IAAMG,UAAU,GAAG,CAACV,OAAD,aAACA,OAAD,cAACA,OAAD,GAAYP,gBAAZ,EAA8BQ,OAA9B,aAA8BA,OAA9B,cAA8BA,OAA9B,GAAyCP,gBAAzC,EAA2Da,KAAK,CAACC,MAAN,CAAaT,KAAxE,CAAnB;IACA,IAAMY,WAAW,GAAGD,UAAU,CAACE,IAAX,GAAkB,CAAlB,CAApB;IAEAf,QAAQ,CAACc,WAAD,CAAR;GAJF;;EAOA,IAAME,kBAAkB,GAAMjB,SAAN,gBAAxB;EAEA,OACEkB,mBAAA,eAAA,MAAA,EACGZ,KAAK,IAAIY,mBAAA,CAACC,KAAD;IAAO,OAAKF;IAAoBX,KAAK,EAAEA;IAAOc,QAAQ,EAAEb;GAAxD,CADZ,EAEEW,mBAAA,CAACjC,mBAAD,MAAA,EACEiC,mBAAA,CAAC9B,eAAD;IACEiC,EAAE,EAAEJ;uBACaK,OAAO,CAACpB,MAAD,aAACA,MAAD,uBAACA,MAAM,CAAEqB,MAAT;IACxBH,QAAQ,EAAEb;IACViB,QAAQ,EAAEhB;IACVP,QAAQ,EAAES;IACVe,MAAM,EAAEZ;IACRa,IAAI,EAAC;IACLvB,KAAK,EAAEA;GART,CADF,EAWGM,cAAc,IACbS,mBAAA,CAACvB,sBAAD,MAAA,EACEuB,mBAAA,CAACS,UAAD;IAAY3B,SAAS,EAAEA;IAAWE,MAAM,EAAEA,MAAF,aAAEA,MAAF,uBAAEA,MAAM,CAAE0B,KAAR;GAA1C,CADF,CAZJ,CAFF,CADF;AAsBD,CA/CD;;;;"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var r,n,t,l=e(require("react")),a=e(require("@propellerads/label")),o=e(require("@propellerads/error-label")),i=e(require("styled-components")),u=require("@propellerads/stylevariables"),
|
|
1
|
+
"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var r,n,t,l=e(require("react")),a=e(require("@propellerads/label")),o=e(require("@propellerads/error-label")),i=e(require("styled-components")),u=require("@propellerads/stylevariables"),d=require("@propellerads/theme-annotation");function s(e,r){return r||(r=e.slice(0)),e.raw=r,e}var p=i.div(r||(r=s(["\n display: flex;\n position: relative;\n width: 82px;\n"]))),c=d.themeAnnotation(i.input(n||(n=s(["\n border: 1px solid ",";\n border-radius: 8px;\n padding: 0 7px;\n font-size: 14px;\n height: 36px;\n\n &[disabled] {\n background-color: ",";\n }\n\n &[data-has-errors='true'] {\n border: 1px solid "," !important;\n color: ",";\n\n &::-webkit-calendar-picker-indicator {\n filter: invert(22%) sepia(63%) saturate(7197%) hue-rotate(353deg) brightness(106%) contrast(87%);\n }\n }\n "])),u.gray80,u.gray95,u.errorColor,u.errorColor),d.Input),m=i.div(t||(t=s(["\n position: absolute;\n right: 1px;\n top: calc(50% - ","px);\n"])),2.5*u.spacing);exports.default=function(e){var r=e.elementId,n=e.onChange,t=e.errors,i=e.value,u=e.minTime,d=e.maxTime,s=e.label,b=e.isRequired,v=e.isReadonly,g=e.showErrorLabel,f=r+"-input-time";return l.createElement(l.Fragment,null,s&&l.createElement(a,{for:f,label:s,required:b}),l.createElement(p,null,l.createElement(c,{id:f,"data-has-errors":Boolean(null==t?void 0:t.length),required:b,disabled:v,onChange:function(e){n(e.target.value)},onBlur:function(e){var r=[null!=u?u:"00:00",null!=d?d:"23:59",e.target.value].sort()[1];n(r)},type:"time",value:i}),g&&l.createElement(m,null,l.createElement(o,{elementId:r,errors:null==t?void 0:t.slice()}))))};
|
|
2
2
|
//# sourceMappingURL=time-picker.cjs.production.min.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"time-picker.cjs.production.min.js","sources":["../src/style.tsx","../src/index.tsx"],"sourcesContent":["import styled, {StyledComponent} from 'styled-components';\nimport {
|
|
1
|
+
{"version":3,"file":"time-picker.cjs.production.min.js","sources":["../src/style.tsx","../src/index.tsx"],"sourcesContent":["import styled, {StyledComponent} from 'styled-components';\nimport {spacing, errorColor, gray80, gray95} from '@propellerads/stylevariables';\nimport {Input, themeAnnotation} from '@propellerads/theme-annotation';\n\nexport const StyledTimeContainer = styled.div`\n display: flex;\n position: relative;\n width: 82px;\n`;\n\nexport const StyledInputTime = themeAnnotation(\n styled.input`\n border: 1px solid ${gray80};\n border-radius: 8px;\n padding: 0 7px;\n font-size: 14px;\n height: 36px;\n\n &[disabled] {\n background-color: ${gray95};\n }\n\n &[data-has-errors='true'] {\n border: 1px solid ${errorColor} !important;\n color: ${errorColor};\n\n &::-webkit-calendar-picker-indicator {\n filter: invert(22%) sepia(63%) saturate(7197%) hue-rotate(353deg) brightness(106%) contrast(87%);\n }\n }\n `,\n Input,\n) as StyledComponent<'input', any>;\n\nexport const StyledTimePickerHelper = styled.div`\n position: absolute;\n right: 1px;\n top: calc(50% - ${spacing * 2.5}px);\n`;\n","import React, {ChangeEvent, FunctionComponent} from 'react';\n\nimport Label from '@propellerads/label';\nimport ErrorLabel from '@propellerads/error-label';\n\nimport {StyledTimeContainer, StyledInputTime, StyledTimePickerHelper} from './style';\nimport {TimePickerProps} from './types';\n\nconst DEFAULT_MIN_TIME = '00:00';\nconst DEFAULT_MAX_TIME = '23:59';\n\nconst TimePicker: FunctionComponent<TimePickerProps> = ({\n elementId,\n onChange,\n errors,\n value,\n minTime,\n maxTime,\n label,\n isRequired,\n isReadonly,\n showErrorLabel,\n}: TimePickerProps) => {\n const onChangeTime = (event: ChangeEvent<HTMLInputElement>) => {\n onChange(event.target.value);\n };\n\n const onChangeCorrectTime = (event: ChangeEvent<HTMLInputElement>) => {\n const timesArray = [minTime ?? DEFAULT_MIN_TIME, maxTime ?? DEFAULT_MAX_TIME, event.target.value];\n const correctTime = timesArray.sort()[1];\n\n onChange(correctTime);\n };\n\n const inputTimeElementId = `${elementId}-input-time`;\n\n return (\n <>\n {label && <Label for={inputTimeElementId} label={label} required={isRequired} />}\n <StyledTimeContainer>\n <StyledInputTime\n id={inputTimeElementId}\n data-has-errors={Boolean(errors?.length)}\n required={isRequired}\n disabled={isReadonly}\n onChange={onChangeTime}\n onBlur={onChangeCorrectTime}\n type=\"time\"\n value={value}\n />\n {showErrorLabel && (\n <StyledTimePickerHelper>\n <ErrorLabel elementId={elementId} errors={errors?.slice()} />\n </StyledTimePickerHelper>\n )}\n </StyledTimeContainer>\n </>\n );\n};\n\nexport default TimePicker;\n"],"names":["StyledTimeContainer","styled","div","StyledInputTime","themeAnnotation","input","gray80","gray95","errorColor","Input","StyledTimePickerHelper","spacing","elementId","onChange","errors","value","minTime","maxTime","label","isRequired","isReadonly","showErrorLabel","inputTimeElementId","React","Label","for","required","id","Boolean","length","disabled","event","target","onBlur","correctTime","sort","type","ErrorLabel","slice"],"mappings":"maAIO,IAAMA,EAAsBC,EAAOC,+EAM7BC,EAAkBC,kBAC7BH,EAAOI,gdACeC,SAOEC,SAIAC,aACXA,cAObC,SAGWC,EAAyBT,EAAOC,sFAGf,IAAVS,2BC1BmC,gBACrDC,IAAAA,UACAC,IAAAA,SACAC,IAAAA,OACAC,IAAAA,MACAC,IAAAA,QACAC,IAAAA,QACAC,IAAAA,MACAC,IAAAA,WACAC,IAAAA,WACAC,IAAAA,eAaMC,EAAwBV,gBAE9B,OACEW,gCACGL,GAASK,gBAACC,GAAMC,IAAKH,EAAoBJ,MAAOA,EAAOQ,SAAUP,IAClEI,gBAACvB,OACCuB,gBAACpB,GACCwB,GAAIL,oBACaM,QAAQd,MAAAA,SAAAA,EAAQe,QACjCH,SAAUP,EACVW,SAAUV,EACVP,SAtBa,SAACkB,GACpBlB,EAASkB,EAAMC,OAAOjB,QAsBhBkB,OAnBoB,SAACF,GAC3B,IACMG,EADa,CAAClB,MAAAA,EAAAA,EApBC,QAoB4BC,MAAAA,EAAAA,EAnB5B,QAmByDc,EAAMC,OAAOjB,OAC5DoB,OAAO,GAEtCtB,EAASqB,IAgBHE,KAAK,OACLrB,MAAOA,IAERM,GACCE,gBAACb,OACCa,gBAACc,GAAWzB,UAAWA,EAAWE,OAAQA,MAAAA,SAAAA,EAAQwB"}
|
package/dist/time-picker.esm.js
CHANGED
|
@@ -15,9 +15,9 @@ function _taggedTemplateLiteralLoose(strings, raw) {
|
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
var _templateObject, _templateObject2, _templateObject3;
|
|
18
|
-
var StyledTimeContainer = /*#__PURE__*/styled.div(_templateObject || (_templateObject = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n
|
|
19
|
-
var StyledInputTime = /*#__PURE__*/themeAnnotation( /*#__PURE__*/styled.input(_templateObject2 || (_templateObject2 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n border: 1px solid ", ";\n border-radius: 8px;\n padding: 0 7px;\n font-size: 14px;\n height: 36px;\n
|
|
20
|
-
var StyledTimePickerHelper = /*#__PURE__*/styled.div(_templateObject3 || (_templateObject3 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n
|
|
18
|
+
var StyledTimeContainer = /*#__PURE__*/styled.div(_templateObject || (_templateObject = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n display: flex;\n position: relative;\n width: 82px;\n"])));
|
|
19
|
+
var StyledInputTime = /*#__PURE__*/themeAnnotation( /*#__PURE__*/styled.input(_templateObject2 || (_templateObject2 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n border: 1px solid ", ";\n border-radius: 8px;\n padding: 0 7px;\n font-size: 14px;\n height: 36px;\n\n &[disabled] {\n background-color: ", ";\n }\n\n &[data-has-errors='true'] {\n border: 1px solid ", " !important;\n color: ", ";\n\n &::-webkit-calendar-picker-indicator {\n filter: invert(22%) sepia(63%) saturate(7197%) hue-rotate(353deg) brightness(106%) contrast(87%);\n }\n }\n "])), gray80, gray95, errorColor, errorColor), Input);
|
|
20
|
+
var StyledTimePickerHelper = /*#__PURE__*/styled.div(_templateObject3 || (_templateObject3 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n position: absolute;\n right: 1px;\n top: calc(50% - ", "px);\n"])), spacing * 2.5);
|
|
21
21
|
|
|
22
22
|
var DEFAULT_MIN_TIME = '00:00';
|
|
23
23
|
var DEFAULT_MAX_TIME = '23:59';
|
|
@@ -44,10 +44,13 @@ var TimePicker = function TimePicker(_ref) {
|
|
|
44
44
|
onChange(correctTime);
|
|
45
45
|
};
|
|
46
46
|
|
|
47
|
+
var inputTimeElementId = elementId + "-input-time";
|
|
47
48
|
return React.createElement(React.Fragment, null, label && React.createElement(Label, {
|
|
49
|
+
"for": inputTimeElementId,
|
|
48
50
|
label: label,
|
|
49
51
|
required: isRequired
|
|
50
52
|
}), React.createElement(StyledTimeContainer, null, React.createElement(StyledInputTime, {
|
|
53
|
+
id: inputTimeElementId,
|
|
51
54
|
"data-has-errors": Boolean(errors === null || errors === void 0 ? void 0 : errors.length),
|
|
52
55
|
required: isRequired,
|
|
53
56
|
disabled: isReadonly,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"time-picker.esm.js","sources":["../src/style.tsx","../src/index.tsx"],"sourcesContent":["import styled, {StyledComponent} from 'styled-components';\nimport {
|
|
1
|
+
{"version":3,"file":"time-picker.esm.js","sources":["../src/style.tsx","../src/index.tsx"],"sourcesContent":["import styled, {StyledComponent} from 'styled-components';\nimport {spacing, errorColor, gray80, gray95} from '@propellerads/stylevariables';\nimport {Input, themeAnnotation} from '@propellerads/theme-annotation';\n\nexport const StyledTimeContainer = styled.div`\n display: flex;\n position: relative;\n width: 82px;\n`;\n\nexport const StyledInputTime = themeAnnotation(\n styled.input`\n border: 1px solid ${gray80};\n border-radius: 8px;\n padding: 0 7px;\n font-size: 14px;\n height: 36px;\n\n &[disabled] {\n background-color: ${gray95};\n }\n\n &[data-has-errors='true'] {\n border: 1px solid ${errorColor} !important;\n color: ${errorColor};\n\n &::-webkit-calendar-picker-indicator {\n filter: invert(22%) sepia(63%) saturate(7197%) hue-rotate(353deg) brightness(106%) contrast(87%);\n }\n }\n `,\n Input,\n) as StyledComponent<'input', any>;\n\nexport const StyledTimePickerHelper = styled.div`\n position: absolute;\n right: 1px;\n top: calc(50% - ${spacing * 2.5}px);\n`;\n","import React, {ChangeEvent, FunctionComponent} from 'react';\n\nimport Label from '@propellerads/label';\nimport ErrorLabel from '@propellerads/error-label';\n\nimport {StyledTimeContainer, StyledInputTime, StyledTimePickerHelper} from './style';\nimport {TimePickerProps} from './types';\n\nconst DEFAULT_MIN_TIME = '00:00';\nconst DEFAULT_MAX_TIME = '23:59';\n\nconst TimePicker: FunctionComponent<TimePickerProps> = ({\n elementId,\n onChange,\n errors,\n value,\n minTime,\n maxTime,\n label,\n isRequired,\n isReadonly,\n showErrorLabel,\n}: TimePickerProps) => {\n const onChangeTime = (event: ChangeEvent<HTMLInputElement>) => {\n onChange(event.target.value);\n };\n\n const onChangeCorrectTime = (event: ChangeEvent<HTMLInputElement>) => {\n const timesArray = [minTime ?? DEFAULT_MIN_TIME, maxTime ?? DEFAULT_MAX_TIME, event.target.value];\n const correctTime = timesArray.sort()[1];\n\n onChange(correctTime);\n };\n\n const inputTimeElementId = `${elementId}-input-time`;\n\n return (\n <>\n {label && <Label for={inputTimeElementId} label={label} required={isRequired} />}\n <StyledTimeContainer>\n <StyledInputTime\n id={inputTimeElementId}\n data-has-errors={Boolean(errors?.length)}\n required={isRequired}\n disabled={isReadonly}\n onChange={onChangeTime}\n onBlur={onChangeCorrectTime}\n type=\"time\"\n value={value}\n />\n {showErrorLabel && (\n <StyledTimePickerHelper>\n <ErrorLabel elementId={elementId} errors={errors?.slice()} />\n </StyledTimePickerHelper>\n )}\n </StyledTimeContainer>\n </>\n );\n};\n\nexport default TimePicker;\n"],"names":["StyledTimeContainer","styled","div","StyledInputTime","themeAnnotation","input","gray80","gray95","errorColor","Input","StyledTimePickerHelper","spacing","DEFAULT_MIN_TIME","DEFAULT_MAX_TIME","TimePicker","elementId","onChange","errors","value","minTime","maxTime","label","isRequired","isReadonly","showErrorLabel","onChangeTime","event","target","onChangeCorrectTime","timesArray","correctTime","sort","inputTimeElementId","React","Label","required","id","Boolean","length","disabled","onBlur","type","ErrorLabel","slice"],"mappings":";;;;;;;;;;;;;;;;;AAIO,IAAMA,mBAAmB,gBAAGC,MAAM,CAACC,GAAV,kJAAzB;AAMA,IAAMC,eAAe,gBAAGC,eAAe,eAC5CH,MAAM,CAACI,KADqC,yhBAEtBC,MAFsB,EASpBC,MAToB,EAapBC,UAboB,EAc/BA,UAd+B,GAqB5CC,KArB4C,CAAvC;AAwBA,IAAMC,sBAAsB,gBAAGT,MAAM,CAACC,GAAV,8JAGfS,OAAO,GAAG,GAHK,CAA5B;;AC1BP,IAAMC,gBAAgB,GAAG,OAAzB;AACA,IAAMC,gBAAgB,GAAG,OAAzB;;AAEA,IAAMC,UAAU,GAAuC,SAAjDA,UAAiD;MACrDC,iBAAAA;MACAC,gBAAAA;MACAC,cAAAA;MACAC,aAAAA;MACAC,eAAAA;MACAC,eAAAA;MACAC,aAAAA;MACAC,kBAAAA;MACAC,kBAAAA;MACAC,sBAAAA;;EAEA,IAAMC,YAAY,GAAG,SAAfA,YAAe,CAACC,KAAD;IACnBV,QAAQ,CAACU,KAAK,CAACC,MAAN,CAAaT,KAAd,CAAR;GADF;;EAIA,IAAMU,mBAAmB,GAAG,SAAtBA,mBAAsB,CAACF,KAAD;IAC1B,IAAMG,UAAU,GAAG,CAACV,OAAD,aAACA,OAAD,cAACA,OAAD,GAAYP,gBAAZ,EAA8BQ,OAA9B,aAA8BA,OAA9B,cAA8BA,OAA9B,GAAyCP,gBAAzC,EAA2Da,KAAK,CAACC,MAAN,CAAaT,KAAxE,CAAnB;IACA,IAAMY,WAAW,GAAGD,UAAU,CAACE,IAAX,GAAkB,CAAlB,CAApB;IAEAf,QAAQ,CAACc,WAAD,CAAR;GAJF;;EAOA,IAAME,kBAAkB,GAAMjB,SAAN,gBAAxB;EAEA,OACEkB,mBAAA,eAAA,MAAA,EACGZ,KAAK,IAAIY,mBAAA,CAACC,KAAD;IAAO,OAAKF;IAAoBX,KAAK,EAAEA;IAAOc,QAAQ,EAAEb;GAAxD,CADZ,EAEEW,mBAAA,CAACjC,mBAAD,MAAA,EACEiC,mBAAA,CAAC9B,eAAD;IACEiC,EAAE,EAAEJ;uBACaK,OAAO,CAACpB,MAAD,aAACA,MAAD,uBAACA,MAAM,CAAEqB,MAAT;IACxBH,QAAQ,EAAEb;IACViB,QAAQ,EAAEhB;IACVP,QAAQ,EAAES;IACVe,MAAM,EAAEZ;IACRa,IAAI,EAAC;IACLvB,KAAK,EAAEA;GART,CADF,EAWGM,cAAc,IACbS,mBAAA,CAACvB,sBAAD,MAAA,EACEuB,mBAAA,CAACS,UAAD;IAAY3B,SAAS,EAAEA;IAAWE,MAAM,EAAEA,MAAF,aAAEA,MAAF,uBAAEA,MAAM,CAAE0B,KAAR;GAA1C,CADF,CAZJ,CAFF,CADF;AAsBD,CA/CD;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@propellerads/time-picker",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"repository": "https://github.com/propellerads/ui-components",
|
|
5
5
|
"author": "n.milantyeva@propellerads.net",
|
|
6
6
|
"license": "MIT",
|
|
@@ -34,10 +34,9 @@
|
|
|
34
34
|
"typescript": "^4.0.2"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
+
"@propellerads/stylevariables": "^1.3.0",
|
|
37
38
|
"@propellerads/error-label": "^2.4.0",
|
|
38
39
|
"@propellerads/label": "^2.1.0",
|
|
39
|
-
"@propellerads/stylevariables": "^1.3.0",
|
|
40
40
|
"@propellerads/theme-annotation": "^1.2.0"
|
|
41
|
-
}
|
|
42
|
-
"gitHead": "82824622b4ac991d78567c473a46b5044cd72035"
|
|
41
|
+
}
|
|
43
42
|
}
|
package/src/index.tsx
CHANGED
|
@@ -3,9 +3,7 @@ import React, {ChangeEvent, FunctionComponent} from 'react';
|
|
|
3
3
|
import Label from '@propellerads/label';
|
|
4
4
|
import ErrorLabel from '@propellerads/error-label';
|
|
5
5
|
|
|
6
|
-
import {
|
|
7
|
-
StyledTimeContainer, StyledInputTime, StyledTimePickerHelper,
|
|
8
|
-
} from './style';
|
|
6
|
+
import {StyledTimeContainer, StyledInputTime, StyledTimePickerHelper} from './style';
|
|
9
7
|
import {TimePickerProps} from './types';
|
|
10
8
|
|
|
11
9
|
const DEFAULT_MIN_TIME = '00:00';
|
|
@@ -34,11 +32,14 @@ const TimePicker: FunctionComponent<TimePickerProps> = ({
|
|
|
34
32
|
onChange(correctTime);
|
|
35
33
|
};
|
|
36
34
|
|
|
35
|
+
const inputTimeElementId = `${elementId}-input-time`;
|
|
36
|
+
|
|
37
37
|
return (
|
|
38
38
|
<>
|
|
39
|
-
{label && <Label label={label} required={isRequired} />}
|
|
39
|
+
{label && <Label for={inputTimeElementId} label={label} required={isRequired} />}
|
|
40
40
|
<StyledTimeContainer>
|
|
41
41
|
<StyledInputTime
|
|
42
|
+
id={inputTimeElementId}
|
|
42
43
|
data-has-errors={Boolean(errors?.length)}
|
|
43
44
|
required={isRequired}
|
|
44
45
|
disabled={isReadonly}
|
|
@@ -49,10 +50,7 @@ const TimePicker: FunctionComponent<TimePickerProps> = ({
|
|
|
49
50
|
/>
|
|
50
51
|
{showErrorLabel && (
|
|
51
52
|
<StyledTimePickerHelper>
|
|
52
|
-
<ErrorLabel
|
|
53
|
-
elementId={elementId}
|
|
54
|
-
errors={errors?.slice()}
|
|
55
|
-
/>
|
|
53
|
+
<ErrorLabel elementId={elementId} errors={errors?.slice()} />
|
|
56
54
|
</StyledTimePickerHelper>
|
|
57
55
|
)}
|
|
58
56
|
</StyledTimeContainer>
|
package/src/style.tsx
CHANGED
|
@@ -1,39 +1,39 @@
|
|
|
1
1
|
import styled, {StyledComponent} from 'styled-components';
|
|
2
|
-
import {
|
|
3
|
-
spacing, errorColor, gray80, gray95,
|
|
4
|
-
} from '@propellerads/stylevariables';
|
|
2
|
+
import {spacing, errorColor, gray80, gray95} from '@propellerads/stylevariables';
|
|
5
3
|
import {Input, themeAnnotation} from '@propellerads/theme-annotation';
|
|
6
4
|
|
|
7
5
|
export const StyledTimeContainer = styled.div`
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
display: flex;
|
|
7
|
+
position: relative;
|
|
8
|
+
width: 82px;
|
|
11
9
|
`;
|
|
12
10
|
|
|
13
|
-
export const StyledInputTime = themeAnnotation(
|
|
11
|
+
export const StyledInputTime = themeAnnotation(
|
|
12
|
+
styled.input`
|
|
14
13
|
border: 1px solid ${gray80};
|
|
15
14
|
border-radius: 8px;
|
|
16
15
|
padding: 0 7px;
|
|
17
16
|
font-size: 14px;
|
|
18
17
|
height: 36px;
|
|
19
|
-
|
|
18
|
+
|
|
20
19
|
&[disabled] {
|
|
21
20
|
background-color: ${gray95};
|
|
22
21
|
}
|
|
23
|
-
|
|
24
|
-
&[data-has-errors=
|
|
22
|
+
|
|
23
|
+
&[data-has-errors='true'] {
|
|
25
24
|
border: 1px solid ${errorColor} !important;
|
|
26
25
|
color: ${errorColor};
|
|
27
|
-
|
|
26
|
+
|
|
28
27
|
&::-webkit-calendar-picker-indicator {
|
|
29
28
|
filter: invert(22%) sepia(63%) saturate(7197%) hue-rotate(353deg) brightness(106%) contrast(87%);
|
|
30
29
|
}
|
|
31
30
|
}
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
`,
|
|
32
|
+
Input,
|
|
33
|
+
) as StyledComponent<'input', any>;
|
|
34
34
|
|
|
35
35
|
export const StyledTimePickerHelper = styled.div`
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
36
|
+
position: absolute;
|
|
37
|
+
right: 1px;
|
|
38
|
+
top: calc(50% - ${spacing * 2.5}px);
|
|
39
39
|
`;
|
package/src/types.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
type TimePickerProps = {
|
|
2
|
-
elementId: string
|
|
3
|
-
onChange: (value: string) => void
|
|
4
|
-
value: string
|
|
5
|
-
minTime?: string | '00:00'
|
|
6
|
-
maxTime?: string | '23:59'
|
|
7
|
-
label?: string | null | undefined
|
|
8
|
-
errors?: Array<string> | undefined
|
|
9
|
-
isRequired?: boolean
|
|
10
|
-
isReadonly?: boolean
|
|
11
|
-
showErrorLabel?: boolean
|
|
12
|
-
}
|
|
2
|
+
elementId: string;
|
|
3
|
+
onChange: (value: string) => void;
|
|
4
|
+
value: string;
|
|
5
|
+
minTime?: string | '00:00';
|
|
6
|
+
maxTime?: string | '23:59';
|
|
7
|
+
label?: string | null | undefined;
|
|
8
|
+
errors?: Array<string> | undefined;
|
|
9
|
+
isRequired?: boolean;
|
|
10
|
+
isReadonly?: boolean;
|
|
11
|
+
showErrorLabel?: boolean;
|
|
12
|
+
};
|
|
13
13
|
|
|
14
14
|
export {TimePickerProps};
|