@chayns-components/core 5.0.0-beta.407 → 5.0.0-beta.408
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/lib/components/filter-buttons/filter-button/FilterButton.styles.js +2 -0
- package/lib/components/filter-buttons/filter-button/FilterButton.styles.js.map +1 -1
- package/lib/components/signature/Signature.js +1 -4
- package/lib/components/signature/Signature.js.map +1 -1
- package/lib/components/slider/Slider.d.ts +21 -1
- package/lib/components/slider/Slider.js +123 -8
- package/lib/components/slider/Slider.js.map +1 -1
- package/lib/components/slider/Slider.styles.d.ts +6 -0
- package/lib/components/slider/Slider.styles.js +62 -27
- package/lib/components/slider/Slider.styles.js.map +1 -1
- package/lib/utils/slider.d.ts +7 -0
- package/lib/utils/slider.js +35 -0
- package/lib/utils/slider.js.map +1 -0
- package/package.json +2 -2
|
@@ -36,6 +36,8 @@ const StyledFilterButtonItemLabel = exports.StyledFilterButtonItemLabel = _style
|
|
|
36
36
|
display: flex;
|
|
37
37
|
gap: 5px;
|
|
38
38
|
align-items: center;
|
|
39
|
+
position: relative;
|
|
40
|
+
z-index: 1;
|
|
39
41
|
`;
|
|
40
42
|
const StyledFilterButtonItemLabelText = exports.StyledFilterButtonItemLabelText = _styledComponents.default.p`
|
|
41
43
|
color: ${_ref3 => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FilterButton.styles.js","names":["_framerMotion","require","_styledComponents","_interopRequireWildcard","_types","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","prototype","hasOwnProperty","call","i","set","StyledFilterButtonItem","exports","styled","div","_ref","size","FilterButtonSize","Normal","_ref2","isSelected","css","StyledFilterButtonItemLabel","StyledFilterButtonItemLabelText","p","_ref3","theme","text","StyledFilterButtonItemBorder","_ref4","shape","FilterButtonItemShape","Round","_ref5","color","headline","StyledMotionFilterButtonItemBackground","motion","_ref6","_ref7","_ref8"],"sources":["../../../../src/components/filter-buttons/filter-button/FilterButton.styles.ts"],"sourcesContent":["import { motion } from 'framer-motion';\nimport type { CSSProperties } from 'react';\nimport styled, { css } from 'styled-components';\nimport type { WithTheme } from '../../color-scheme-provider/ColorSchemeProvider';\nimport { FilterButtonItemShape, FilterButtonSize } from '../types';\n\ntype StyledFilterButtonItemProps = WithTheme<{ size: FilterButtonSize; isSelected: boolean }>;\n\nexport const StyledFilterButtonItem = styled.div<StyledFilterButtonItemProps>`\n position: relative;\n font-size: ${({ size }) => (size === FilterButtonSize.Normal ? 15 : 12)}px;\n cursor: pointer;\n user-select: none;\n padding: 3px 14px;\n\n &:hover > div:last-child {\n ${({ isSelected }) =>\n !isSelected &&\n css`\n opacity: 0.2;\n `}\n }\n`;\n\nexport const StyledFilterButtonItemLabel = styled.div`\n display: flex;\n gap: 5px;\n align-items: center;\n`;\n\ntype StyledFilterButtonItemLabelTextProps = WithTheme<unknown>;\n\nexport const StyledFilterButtonItemLabelText = styled.p<StyledFilterButtonItemLabelTextProps>`\n color: ${({ theme }: StyledFilterButtonItemLabelTextProps) => theme.text};\n margin-top: 2px;\n`;\n\ntype StyledFilterButtonItemBorderProps = WithTheme<{\n shape: FilterButtonItemShape;\n color: CSSProperties['color'];\n isSelected: boolean;\n}>;\n\nexport const StyledFilterButtonItemBorder = styled.div<StyledFilterButtonItemBorderProps>`\n position: absolute;\n top: 0;\n left: 0;\n height: 100%;\n width: 100%;\n opacity: 0.4;\n z-index: 0;\n border-radius: ${({ shape }) => (shape === FilterButtonItemShape.Round ? 100 : 0)}px;\n ${({ color, theme, isSelected }: StyledFilterButtonItemBorderProps) =>\n !isSelected &&\n css`\n border-width: 1px;\n border-style: solid;\n border-color: ${color ?? theme.headline};\n `};\n`;\n\ntype StyledFilterButtonItemBackgroundProps = WithTheme<{\n shape: FilterButtonItemShape;\n color: CSSProperties['color'];\n isSelected: boolean;\n}>;\n\nexport const StyledMotionFilterButtonItemBackground = styled(\n motion.div\n)<StyledFilterButtonItemBackgroundProps>`\n position: absolute;\n top: 0;\n left: 0;\n height: 100%;\n width: 100%;\n z-index: 0;\n opacity: ${({ isSelected }) => (isSelected ? 0.4 : 0)};\n transition: opacity 0.5s ease;\n border-radius: ${({ shape }) => (shape === FilterButtonItemShape.Round ? 100 : 0)}px;\n background-color: ${({ color, theme }: StyledFilterButtonItemBackgroundProps) =>\n color ?? theme.headline};\n`;\n"],"mappings":";;;;;;AAAA,IAAAA,aAAA,GAAAC,OAAA;AAEA,IAAAC,iBAAA,GAAAC,uBAAA,CAAAF,OAAA;AAEA,IAAAG,MAAA,GAAAH,OAAA;AAAmE,SAAAI,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,CAAA,WAAAA,CAAA,GAAAG,CAAA,GAAAD,CAAA,KAAAF,CAAA;AAAA,SAAAH,wBAAAG,CAAA,EAAAE,CAAA,SAAAA,CAAA,IAAAF,CAAA,IAAAA,CAAA,CAAAI,UAAA,SAAAJ,CAAA,eAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,WAAAK,OAAA,EAAAL,CAAA,QAAAG,CAAA,GAAAJ,wBAAA,CAAAG,CAAA,OAAAC,CAAA,IAAAA,CAAA,CAAAG,GAAA,CAAAN,CAAA,UAAAG,CAAA,CAAAI,GAAA,CAAAP,CAAA,OAAAQ,CAAA,KAAAC,SAAA,UAAAC,CAAA,GAAAC,MAAA,CAAAC,cAAA,IAAAD,MAAA,CAAAE,wBAAA,WAAAC,CAAA,IAAAd,CAAA,oBAAAc,CAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAjB,CAAA,EAAAc,CAAA,SAAAI,CAAA,GAAAR,CAAA,GAAAC,MAAA,CAAAE,wBAAA,CAAAb,CAAA,EAAAc,CAAA,UAAAI,CAAA,KAAAA,CAAA,CAAAX,GAAA,IAAAW,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AC;AAAA,CAAE;AACtF,MAAMC,KAAA;EAAA,IAAC;IAAEC,KAAK;IAAER,KAAK;IAAEN;EAA8C,CAAC,GAAAa,KAAA;EAAA,OAC9D,CAACb,UAAU,IACX,IAAAC,qBAAG,CAAC;AACZ;AACA;AACA,4BAA4Ba,KAAK,IAAIR,KAAK,CAACS,QAAS;AACpD,SAAS;AAAA,CAAC;AACV,CAAC;AAQM,MAAMC,sCAAsC,GAAAxB,OAAA,CAAAwB,sCAAA,GAAG,IAAAvB,yBAAM,EACxDwB,oBAAM,CAACvB,GACX,CAAyC;AACzC;AACA;AACA;AACA;AACA;AACA;AACA,eAAewB,KAAA;EAAA,IAAC;IAAElB;EAAW,CAAC,GAAAkB,KAAA;EAAA,OAAMlB,UAAU,GAAG,GAAG,GAAG,CAAC;AAAA,CAAE;AAC1D;AACA,qBAAqBmB,KAAA;EAAA,IAAC;IAAET;EAAM,CAAC,GAAAS,KAAA;EAAA,OAAMT,KAAK,KAAKC,4BAAqB,CAACC,KAAK,GAAG,GAAG,GAAG,CAAC;AAAA,CAAE;AACtF,wBAAwBQ,KAAA;EAAA,IAAC;IAAEN,KAAK;IAAER;EAA6C,CAAC,GAAAc,KAAA;EAAA,OACxEN,KAAK,IAAIR,KAAK,CAACS,QAAQ;AAAA,CAAC;AAChC,CAAC"}
|
|
1
|
+
{"version":3,"file":"FilterButton.styles.js","names":["_framerMotion","require","_styledComponents","_interopRequireWildcard","_types","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","prototype","hasOwnProperty","call","i","set","StyledFilterButtonItem","exports","styled","div","_ref","size","FilterButtonSize","Normal","_ref2","isSelected","css","StyledFilterButtonItemLabel","StyledFilterButtonItemLabelText","p","_ref3","theme","text","StyledFilterButtonItemBorder","_ref4","shape","FilterButtonItemShape","Round","_ref5","color","headline","StyledMotionFilterButtonItemBackground","motion","_ref6","_ref7","_ref8"],"sources":["../../../../src/components/filter-buttons/filter-button/FilterButton.styles.ts"],"sourcesContent":["import { motion } from 'framer-motion';\nimport type { CSSProperties } from 'react';\nimport styled, { css } from 'styled-components';\nimport type { WithTheme } from '../../color-scheme-provider/ColorSchemeProvider';\nimport { FilterButtonItemShape, FilterButtonSize } from '../types';\n\ntype StyledFilterButtonItemProps = WithTheme<{ size: FilterButtonSize; isSelected: boolean }>;\n\nexport const StyledFilterButtonItem = styled.div<StyledFilterButtonItemProps>`\n position: relative;\n font-size: ${({ size }) => (size === FilterButtonSize.Normal ? 15 : 12)}px;\n cursor: pointer;\n user-select: none;\n padding: 3px 14px;\n\n &:hover > div:last-child {\n ${({ isSelected }) =>\n !isSelected &&\n css`\n opacity: 0.2;\n `}\n }\n`;\n\nexport const StyledFilterButtonItemLabel = styled.div`\n display: flex;\n gap: 5px;\n align-items: center;\n position: relative;\n z-index: 1;\n`;\n\ntype StyledFilterButtonItemLabelTextProps = WithTheme<unknown>;\n\nexport const StyledFilterButtonItemLabelText = styled.p<StyledFilterButtonItemLabelTextProps>`\n color: ${({ theme }: StyledFilterButtonItemLabelTextProps) => theme.text};\n margin-top: 2px;\n`;\n\ntype StyledFilterButtonItemBorderProps = WithTheme<{\n shape: FilterButtonItemShape;\n color: CSSProperties['color'];\n isSelected: boolean;\n}>;\n\nexport const StyledFilterButtonItemBorder = styled.div<StyledFilterButtonItemBorderProps>`\n position: absolute;\n top: 0;\n left: 0;\n height: 100%;\n width: 100%;\n opacity: 0.4;\n z-index: 0;\n border-radius: ${({ shape }) => (shape === FilterButtonItemShape.Round ? 100 : 0)}px;\n ${({ color, theme, isSelected }: StyledFilterButtonItemBorderProps) =>\n !isSelected &&\n css`\n border-width: 1px;\n border-style: solid;\n border-color: ${color ?? theme.headline};\n `};\n`;\n\ntype StyledFilterButtonItemBackgroundProps = WithTheme<{\n shape: FilterButtonItemShape;\n color: CSSProperties['color'];\n isSelected: boolean;\n}>;\n\nexport const StyledMotionFilterButtonItemBackground = styled(\n motion.div\n)<StyledFilterButtonItemBackgroundProps>`\n position: absolute;\n top: 0;\n left: 0;\n height: 100%;\n width: 100%;\n z-index: 0;\n opacity: ${({ isSelected }) => (isSelected ? 0.4 : 0)};\n transition: opacity 0.5s ease;\n border-radius: ${({ shape }) => (shape === FilterButtonItemShape.Round ? 100 : 0)}px;\n background-color: ${({ color, theme }: StyledFilterButtonItemBackgroundProps) =>\n color ?? theme.headline};\n`;\n"],"mappings":";;;;;;AAAA,IAAAA,aAAA,GAAAC,OAAA;AAEA,IAAAC,iBAAA,GAAAC,uBAAA,CAAAF,OAAA;AAEA,IAAAG,MAAA,GAAAH,OAAA;AAAmE,SAAAI,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,CAAA,WAAAA,CAAA,GAAAG,CAAA,GAAAD,CAAA,KAAAF,CAAA;AAAA,SAAAH,wBAAAG,CAAA,EAAAE,CAAA,SAAAA,CAAA,IAAAF,CAAA,IAAAA,CAAA,CAAAI,UAAA,SAAAJ,CAAA,eAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,WAAAK,OAAA,EAAAL,CAAA,QAAAG,CAAA,GAAAJ,wBAAA,CAAAG,CAAA,OAAAC,CAAA,IAAAA,CAAA,CAAAG,GAAA,CAAAN,CAAA,UAAAG,CAAA,CAAAI,GAAA,CAAAP,CAAA,OAAAQ,CAAA,KAAAC,SAAA,UAAAC,CAAA,GAAAC,MAAA,CAAAC,cAAA,IAAAD,MAAA,CAAAE,wBAAA,WAAAC,CAAA,IAAAd,CAAA,oBAAAc,CAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAjB,CAAA,EAAAc,CAAA,SAAAI,CAAA,GAAAR,CAAA,GAAAC,MAAA,CAAAE,wBAAA,CAAAb,CAAA,EAAAc,CAAA,UAAAI,CAAA,KAAAA,CAAA,CAAAX,GAAA,IAAAW,CAAA,C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CAAC;AAAA,CAAE;AACtF,MAAMC,KAAA;EAAA,IAAC;IAAEC,KAAK;IAAER,KAAK;IAAEN;EAA8C,CAAC,GAAAa,KAAA;EAAA,OAC9D,CAACb,UAAU,IACX,IAAAC,qBAAG,CAAC;AACZ;AACA;AACA,4BAA4Ba,KAAK,IAAIR,KAAK,CAACS,QAAS;AACpD,SAAS;AAAA,CAAC;AACV,CAAC;AAQM,MAAMC,sCAAsC,GAAAxB,OAAA,CAAAwB,sCAAA,GAAG,IAAAvB,yBAAM,EACxDwB,oBAAM,CAACvB,GACX,CAAyC;AACzC;AACA;AACA;AACA;AACA;AACA;AACA,eAAewB,KAAA;EAAA,IAAC;IAAElB;EAAW,CAAC,GAAAkB,KAAA;EAAA,OAAMlB,UAAU,GAAG,GAAG,GAAG,CAAC;AAAA,CAAE;AAC1D;AACA,qBAAqBmB,KAAA;EAAA,IAAC;IAAET;EAAM,CAAC,GAAAS,KAAA;EAAA,OAAMT,KAAK,KAAKC,4BAAqB,CAACC,KAAK,GAAG,GAAG,GAAG,CAAC;AAAA,CAAE;AACtF,wBAAwBQ,KAAA;EAAA,IAAC;IAAEN,KAAK;IAAER;EAA6C,CAAC,GAAAc,KAAA;EAAA,OACxEN,KAAK,IAAIR,KAAK,CAACS,QAAQ;AAAA,CAAC;AAChC,CAAC"}
|
|
@@ -28,7 +28,6 @@ const Signature = /*#__PURE__*/(0, _react.forwardRef)((_ref, ref) => {
|
|
|
28
28
|
(0, _react.useEffect)(() => {
|
|
29
29
|
const loadUserSignature = async () => {
|
|
30
30
|
await (0, _get.getUserSignature)().then(signature => {
|
|
31
|
-
console.debug('getUserSignature', signature);
|
|
32
31
|
setSignatureUrl(signature);
|
|
33
32
|
});
|
|
34
33
|
};
|
|
@@ -45,13 +44,12 @@ const Signature = /*#__PURE__*/(0, _react.forwardRef)((_ref, ref) => {
|
|
|
45
44
|
buttonType: 0
|
|
46
45
|
}]
|
|
47
46
|
}).then(async result => {
|
|
48
|
-
console.debug('Dialog result', result);
|
|
49
47
|
if (result.buttonType === 1 && result.value) {
|
|
50
48
|
await (0, _put.putUserSignature)(result.value).then(success => {
|
|
51
|
-
console.debug('putUserSignature', success);
|
|
52
49
|
if (success) {
|
|
53
50
|
setSignatureUrl(result.value);
|
|
54
51
|
if (shouldSubscribe) {
|
|
52
|
+
setHasSubscribed(true);
|
|
55
53
|
if (typeof onSubscribe === 'function') {
|
|
56
54
|
onSubscribe();
|
|
57
55
|
}
|
|
@@ -68,7 +66,6 @@ const Signature = /*#__PURE__*/(0, _react.forwardRef)((_ref, ref) => {
|
|
|
68
66
|
}, [handleCallDialog]);
|
|
69
67
|
const handleDelete = (0, _react.useCallback)(async () => {
|
|
70
68
|
await (0, _delete.deleteUserSignature)().then(success => {
|
|
71
|
-
console.debug('deleteUserSignature', success);
|
|
72
69
|
if (success) {
|
|
73
70
|
setSignatureUrl(undefined);
|
|
74
71
|
if (typeof onRemove === 'function') {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Signature.js","names":["_react","_interopRequireWildcard","require","_Button","_interopRequireDefault","_Signature","_put","_delete","_get","_Icon","obj","__esModule","default","_getRequireWildcardCache","e","WeakMap","r","t","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","prototype","hasOwnProperty","call","i","set","Signature","forwardRef","_ref","ref","onEdit","onRemove","onUnsubscribe","onSubscribe","buttonText","isDisabled","signatureUrl","setSignatureUrl","useState","undefined","hasSubscribed","setHasSubscribed","useEffect","loadUserSignature","getUserSignature","then","signature","console","debug","handleCallDialog","useCallback","shouldSubscribe","chayns","dialog","buttons","text","buttonType","result","value","putUserSignature","success","handleEdit","handleDelete","deleteUserSignature","handleClick","handleUnSubscribe","useImperativeHandle","edit","delete","createElement","StyledSignature","onClick","StyledSignatureImageWrapper","StyledSignatureImage","src","StyledSignatureDeleteIconWrapper","icons","size","displayName","_default","exports"],"sources":["../../../src/components/signature/Signature.tsx"],"sourcesContent":["import React, { forwardRef, useCallback, useEffect, useImperativeHandle, useState } from 'react';\nimport Button from '../button/Button';\nimport {\n StyledSignature,\n StyledSignatureDeleteIconWrapper,\n StyledSignatureImage,\n StyledSignatureImageWrapper,\n} from './Signature.styles';\nimport { putUserSignature } from '../../api/signature/put';\nimport { deleteUserSignature } from '../../api/signature/delete';\nimport { getUserSignature } from '../../api/signature/get';\nimport Icon from '../icon/Icon';\n\nexport interface SignatureRef {\n edit: VoidFunction;\n delete: VoidFunction;\n}\n\nexport type SignatureProps = {\n /**\n * The text that should be displayed inside the button.\n */\n buttonText: string;\n /**\n * Whether the button is disabled.\n */\n isDisabled?: boolean;\n /**\n * Function to be executed when the signature is edited.\n */\n onEdit?: (signature: string) => void;\n /**\n * Function to be executed when the user deletes the signature.\n */\n onRemove?: () => void;\n /**\n * Function to be executed when the user subscribes.\n */\n onSubscribe?: () => void;\n /**\n * Function to be executed when the user unsubscribes.\n */\n onUnsubscribe?: () => void;\n};\n\nconst Signature = forwardRef<SignatureRef, SignatureProps>(\n ({ onEdit, onRemove, onUnsubscribe, onSubscribe, buttonText, isDisabled }, ref) => {\n const [signatureUrl, setSignatureUrl] = useState<string | undefined>(undefined);\n const [hasSubscribed, setHasSubscribed] = useState(false);\n\n useEffect(() => {\n const loadUserSignature = async () => {\n await getUserSignature().then((signature) => {\n console.debug('getUserSignature', signature);\n setSignatureUrl(signature);\n });\n };\n\n void loadUserSignature();\n }, []);\n\n const handleCallDialog = useCallback(\n async (shouldSubscribe: boolean) => {\n // ToDo replace with new dialog if ready\n await chayns.dialog\n .signature({\n buttons: [\n {\n text: 'Speichern',\n buttonType: 1,\n },\n {\n text: 'Abbrechen',\n buttonType: 0,\n },\n ],\n })\n .then(async (result) => {\n console.debug('Dialog result', result);\n if (result.buttonType === 1 && result.value) {\n await putUserSignature(result.value).then((success) => {\n console.debug('putUserSignature', success);\n if (success) {\n setSignatureUrl(result.value);\n\n if (shouldSubscribe) {\n if (typeof onSubscribe === 'function') {\n onSubscribe();\n }\n } else if (typeof onEdit === 'function') {\n onEdit(result.value);\n }\n }\n });\n }\n });\n },\n [onEdit, onSubscribe]\n );\n\n const handleEdit = useCallback(() => {\n void handleCallDialog(false);\n }, [handleCallDialog]);\n\n const handleDelete = useCallback(async () => {\n await deleteUserSignature().then((success) => {\n console.debug('deleteUserSignature', success);\n if (success) {\n setSignatureUrl(undefined);\n\n if (typeof onRemove === 'function') {\n onRemove();\n }\n }\n });\n }, [onRemove]);\n\n const handleClick = useCallback(() => {\n if (signatureUrl) {\n setHasSubscribed(true);\n\n if (typeof onSubscribe === 'function') {\n onSubscribe();\n }\n } else {\n void handleCallDialog(true);\n }\n }, [handleCallDialog, onSubscribe, signatureUrl]);\n\n const handleUnSubscribe = () => {\n setHasSubscribed(false);\n setSignatureUrl(undefined);\n\n if (typeof onUnsubscribe === 'function') {\n onUnsubscribe();\n }\n };\n\n useImperativeHandle(\n ref,\n () => ({\n edit: handleEdit,\n delete: handleDelete,\n }),\n [handleDelete, handleEdit]\n );\n\n return (\n <StyledSignature>\n {!hasSubscribed ? (\n <Button isDisabled={isDisabled} onClick={handleClick}>\n {buttonText}\n </Button>\n ) : (\n <StyledSignatureImageWrapper>\n <StyledSignatureImage src={signatureUrl} />\n <StyledSignatureDeleteIconWrapper>\n <Icon icons={['ts-wrong']} size={20} onClick={handleUnSubscribe} />\n </StyledSignatureDeleteIconWrapper>\n </StyledSignatureImageWrapper>\n )}\n </StyledSignature>\n );\n }\n);\n\nSignature.displayName = 'Signature';\n\nexport default Signature;\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,OAAA,GAAAC,sBAAA,CAAAF,OAAA;AACA,IAAAG,UAAA,GAAAH,OAAA;AAMA,IAAAI,IAAA,GAAAJ,OAAA;AACA,IAAAK,OAAA,GAAAL,OAAA;AACA,IAAAM,IAAA,GAAAN,OAAA;AACA,IAAAO,KAAA,GAAAL,sBAAA,CAAAF,OAAA;AAAgC,SAAAE,uBAAAM,GA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RequireDefault","_Signature","_put","_delete","_get","_Icon","obj","__esModule","default","_getRequireWildcardCache","e","WeakMap","r","t","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","prototype","hasOwnProperty","call","i","set","Signature","forwardRef","_ref","ref","onEdit","onRemove","onUnsubscribe","onSubscribe","buttonText","isDisabled","signatureUrl","setSignatureUrl","useState","undefined","hasSubscribed","setHasSubscribed","useEffect","loadUserSignature","getUserSignature","then","signature","handleCallDialog","useCallback","shouldSubscribe","chayns","dialog","buttons","text","buttonType","result","value","putUserSignature","success","handleEdit","handleDelete","deleteUserSignature","handleClick","handleUnSubscribe","useImperativeHandle","edit","delete","createElement","StyledSignature","onClick","StyledSignatureImageWrapper","StyledSignatureImage","src","StyledSignatureDeleteIconWrapper","icons","size","displayName","_default","exports"],"sources":["../../../src/components/signature/Signature.tsx"],"sourcesContent":["import React, { forwardRef, useCallback, useEffect, useImperativeHandle, useState } from 'react';\nimport Button from '../button/Button';\nimport {\n StyledSignature,\n StyledSignatureDeleteIconWrapper,\n StyledSignatureImage,\n StyledSignatureImageWrapper,\n} from './Signature.styles';\nimport { putUserSignature } from '../../api/signature/put';\nimport { deleteUserSignature } from '../../api/signature/delete';\nimport { getUserSignature } from '../../api/signature/get';\nimport Icon from '../icon/Icon';\n\nexport interface SignatureRef {\n edit: VoidFunction;\n delete: VoidFunction;\n}\n\nexport type SignatureProps = {\n /**\n * The text that should be displayed inside the button.\n */\n buttonText: string;\n /**\n * Whether the button is disabled.\n */\n isDisabled?: boolean;\n /**\n * Function to be executed when the signature is edited.\n */\n onEdit?: (signature: string) => void;\n /**\n * Function to be executed when the user deletes the signature.\n */\n onRemove?: () => void;\n /**\n * Function to be executed when the user subscribes.\n */\n onSubscribe?: () => void;\n /**\n * Function to be executed when the user unsubscribes.\n */\n onUnsubscribe?: () => void;\n};\n\nconst Signature = forwardRef<SignatureRef, SignatureProps>(\n ({ onEdit, onRemove, onUnsubscribe, onSubscribe, buttonText, isDisabled }, ref) => {\n const [signatureUrl, setSignatureUrl] = useState<string | undefined>(undefined);\n const [hasSubscribed, setHasSubscribed] = useState(false);\n\n useEffect(() => {\n const loadUserSignature = async () => {\n await getUserSignature().then((signature) => {\n setSignatureUrl(signature);\n });\n };\n\n void loadUserSignature();\n }, []);\n\n const handleCallDialog = useCallback(\n async (shouldSubscribe: boolean) => {\n // ToDo replace with new dialog if ready\n await chayns.dialog\n .signature({\n buttons: [\n {\n text: 'Speichern',\n buttonType: 1,\n },\n {\n text: 'Abbrechen',\n buttonType: 0,\n },\n ],\n })\n .then(async (result) => {\n if (result.buttonType === 1 && result.value) {\n await putUserSignature(result.value).then((success) => {\n if (success) {\n setSignatureUrl(result.value);\n\n if (shouldSubscribe) {\n setHasSubscribed(true);\n\n if (typeof onSubscribe === 'function') {\n onSubscribe();\n }\n } else if (typeof onEdit === 'function') {\n onEdit(result.value);\n }\n }\n });\n }\n });\n },\n [onEdit, onSubscribe]\n );\n\n const handleEdit = useCallback(() => {\n void handleCallDialog(false);\n }, [handleCallDialog]);\n\n const handleDelete = useCallback(async () => {\n await deleteUserSignature().then((success) => {\n if (success) {\n setSignatureUrl(undefined);\n\n if (typeof onRemove === 'function') {\n onRemove();\n }\n }\n });\n }, [onRemove]);\n\n const handleClick = useCallback(() => {\n if (signatureUrl) {\n setHasSubscribed(true);\n\n if (typeof onSubscribe === 'function') {\n onSubscribe();\n }\n } else {\n void handleCallDialog(true);\n }\n }, [handleCallDialog, onSubscribe, signatureUrl]);\n\n const handleUnSubscribe = () => {\n setHasSubscribed(false);\n setSignatureUrl(undefined);\n\n if (typeof onUnsubscribe === 'function') {\n onUnsubscribe();\n }\n };\n\n useImperativeHandle(\n ref,\n () => ({\n edit: handleEdit,\n delete: handleDelete,\n }),\n [handleDelete, handleEdit]\n );\n\n return (\n <StyledSignature>\n {!hasSubscribed ? (\n <Button isDisabled={isDisabled} onClick={handleClick}>\n {buttonText}\n </Button>\n ) : (\n <StyledSignatureImageWrapper>\n <StyledSignatureImage src={signatureUrl} />\n <StyledSignatureDeleteIconWrapper>\n <Icon icons={['ts-wrong']} size={20} onClick={handleUnSubscribe} />\n </StyledSignatureDeleteIconWrapper>\n </StyledSignatureImageWrapper>\n )}\n </StyledSignature>\n );\n }\n);\n\nSignature.displayName = 'Signature';\n\nexport default Signature;\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,OAAA,GAAAC,sBAAA,CAAAF,OAAA;AACA,IAAAG,UAAA,GAAAH,OAAA;AAMA,IAAAI,IAAA,GAAAJ,OAAA;AACA,IAAAK,OAAA,GAAAL,OAAA;AACA,IAAAM,IAAA,GAAAN,OAAA;AACA,IAAAO,KAAA,GAAAL,sBAAA,CAAAF,OAAA;AAAgC,SAAAE,uBAAAM,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAAA,SAAAG,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,CAAA,WAAAA,CAAA,GAAAG,CAAA,GAAAD,CAAA,KAAAF,CAAA;AAAA,SAAAb,wBAAAa,CAAA,EAAAE,CAAA,SAAAA,CAAA,IAAAF,CAAA,IAAAA,CAAA,CAAAH,UAAA,SAAAG,CAAA,eAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,WAAAF,OAAA,EAAAE,CAAA,QAAAG,CAAA,GAAAJ,wBAAA,CAAAG,CAAA,OAAAC,CAAA,IAAAA,CAAA,CAAAC,GAAA,CAAAJ,CAAA,UAAAG,CAAA,CAAAE,GAAA,CAAAL,CAAA,OAAAM,CAAA,KAAAC,SAAA,UAAAC,CAAA,GAAAC,MAAA,CAAAC,cAAA,IAAAD,MAAA,CAAAE,wBAAA,WAAAC,CAAA,IAAAZ,CAAA,oBAAAY,CAAA,IAAAH,MAAA,CA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,KAAK,EAAE,CAAC,UAAU,CAAE;IAACC,IAAI,EAAE,EAAG;IAACN,OAAO,EAAEN;EAAkB,CAAE,CACpC,CACT,CAEpB,CAAC;AAE1B,CACJ,CAAC;AAEDrC,SAAS,CAACkD,WAAW,GAAG,WAAW;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAAxE,OAAA,GAErBoB,SAAS"}
|
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
import { FC } from 'react';
|
|
2
|
+
export interface SliderInterval {
|
|
3
|
+
maxValue: number;
|
|
4
|
+
minValue: number;
|
|
5
|
+
}
|
|
2
6
|
export type SliderProps = {
|
|
7
|
+
/**
|
|
8
|
+
* The range that can be selected with two thumbs..
|
|
9
|
+
*/
|
|
10
|
+
interval?: SliderInterval;
|
|
3
11
|
/**
|
|
4
12
|
* The maximum value of the slider.
|
|
5
13
|
*/
|
|
@@ -11,7 +19,19 @@ export type SliderProps = {
|
|
|
11
19
|
/**
|
|
12
20
|
* Function that will be executed when the value is changed.
|
|
13
21
|
*/
|
|
14
|
-
onChange?: (value
|
|
22
|
+
onChange?: (value?: number, interval?: SliderInterval) => void;
|
|
23
|
+
/**
|
|
24
|
+
* Whether the current value should be displayed inside the slider thumb.
|
|
25
|
+
*/
|
|
26
|
+
shouldShowThumbLable?: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* The steps of the slider.
|
|
29
|
+
*/
|
|
30
|
+
steps?: number;
|
|
31
|
+
/**
|
|
32
|
+
* A function to format the thumb lable.
|
|
33
|
+
*/
|
|
34
|
+
thumbLableFormatter?: (value: number) => string;
|
|
15
35
|
/**
|
|
16
36
|
* the Value that the slider should have.
|
|
17
37
|
*/
|
|
@@ -6,6 +6,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
var _react = _interopRequireWildcard(require("react"));
|
|
8
8
|
var _Slider = require("./Slider.styles");
|
|
9
|
+
var _slider = require("../../utils/slider");
|
|
10
|
+
var _styledComponents = require("styled-components");
|
|
9
11
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
10
12
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
11
13
|
const Slider = _ref => {
|
|
@@ -13,9 +15,17 @@ const Slider = _ref => {
|
|
|
13
15
|
maxValue,
|
|
14
16
|
minValue,
|
|
15
17
|
value,
|
|
16
|
-
onChange
|
|
18
|
+
onChange,
|
|
19
|
+
interval,
|
|
20
|
+
thumbLableFormatter,
|
|
21
|
+
shouldShowThumbLable = false,
|
|
22
|
+
steps = 1
|
|
17
23
|
} = _ref;
|
|
18
|
-
const [
|
|
24
|
+
const [fromValue, setFromValue] = (0, _react.useState)(0);
|
|
25
|
+
const [toValue, setToValue] = (0, _react.useState)(maxValue);
|
|
26
|
+
const fromSliderRef = (0, _react.useRef)(null);
|
|
27
|
+
const toSliderRef = (0, _react.useRef)(null);
|
|
28
|
+
const theme = (0, _styledComponents.useTheme)();
|
|
19
29
|
|
|
20
30
|
/**
|
|
21
31
|
* This function sets the value
|
|
@@ -25,26 +35,131 @@ const Slider = _ref => {
|
|
|
25
35
|
return;
|
|
26
36
|
}
|
|
27
37
|
if (value >= minValue && value <= maxValue) {
|
|
28
|
-
|
|
38
|
+
setFromValue(value);
|
|
29
39
|
}
|
|
30
40
|
}, [maxValue, minValue, value]);
|
|
41
|
+
(0, _react.useEffect)(() => {
|
|
42
|
+
if (fromValue > toValue) {
|
|
43
|
+
setFromValue(toValue);
|
|
44
|
+
}
|
|
45
|
+
if (toValue < fromValue) {
|
|
46
|
+
setToValue(fromValue);
|
|
47
|
+
}
|
|
48
|
+
}, [fromValue, toValue]);
|
|
49
|
+
const handleControlFromSlider = (0, _react.useCallback)(event => {
|
|
50
|
+
if (!fromSliderRef.current || !toSliderRef.current) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
setFromValue(Number(event.target.value));
|
|
54
|
+
const from = Number(fromSliderRef.current.value);
|
|
55
|
+
const to = Number(toSliderRef.current.value);
|
|
56
|
+
if (typeof onChange === 'function') {
|
|
57
|
+
onChange(undefined, {
|
|
58
|
+
maxValue: to,
|
|
59
|
+
minValue: from
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
(0, _slider.fillSlider)({
|
|
63
|
+
toSlider: toSliderRef.current,
|
|
64
|
+
fromSlider: fromSliderRef.current,
|
|
65
|
+
theme
|
|
66
|
+
});
|
|
67
|
+
if (from > to) {
|
|
68
|
+
fromSliderRef.current.value = String(to);
|
|
69
|
+
} else {
|
|
70
|
+
fromSliderRef.current.value = String(from);
|
|
71
|
+
}
|
|
72
|
+
}, [onChange, theme]);
|
|
73
|
+
const handleControlToSlider = (0, _react.useCallback)(event => {
|
|
74
|
+
if (!fromSliderRef.current || !toSliderRef.current) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
setToValue(Number(event.target.value));
|
|
78
|
+
const from = Number(fromSliderRef.current.value);
|
|
79
|
+
const to = Number(toSliderRef.current.value);
|
|
80
|
+
if (typeof onChange === 'function') {
|
|
81
|
+
onChange(undefined, {
|
|
82
|
+
maxValue: to,
|
|
83
|
+
minValue: from
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
(0, _slider.fillSlider)({
|
|
87
|
+
toSlider: toSliderRef.current,
|
|
88
|
+
fromSlider: fromSliderRef.current,
|
|
89
|
+
theme
|
|
90
|
+
});
|
|
91
|
+
if (from <= to) {
|
|
92
|
+
toSliderRef.current.value = String(to);
|
|
93
|
+
} else {
|
|
94
|
+
toSliderRef.current.value = String(from);
|
|
95
|
+
}
|
|
96
|
+
}, [onChange, theme]);
|
|
97
|
+
(0, _react.useEffect)(() => {
|
|
98
|
+
if (!fromSliderRef.current || !toSliderRef.current || !interval) {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
setFromValue(interval.minValue);
|
|
102
|
+
setToValue(interval.maxValue);
|
|
103
|
+
fromSliderRef.current.value = String(interval.minValue);
|
|
104
|
+
toSliderRef.current.value = String(interval.maxValue);
|
|
105
|
+
(0, _slider.fillSlider)({
|
|
106
|
+
fromSlider: fromSliderRef.current,
|
|
107
|
+
toSlider: toSliderRef.current,
|
|
108
|
+
theme
|
|
109
|
+
});
|
|
110
|
+
// Note: interval can´t be in the deps because of rerender
|
|
111
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
112
|
+
}, [theme]);
|
|
31
113
|
|
|
32
114
|
/**
|
|
33
115
|
* This function updates the value
|
|
34
116
|
*/
|
|
35
117
|
const handleInputChange = (0, _react.useCallback)(event => {
|
|
36
|
-
|
|
118
|
+
const newValue = Number(event.target.value);
|
|
119
|
+
if (interval) {
|
|
120
|
+
handleControlFromSlider(event);
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
setFromValue(newValue);
|
|
37
124
|
if (onChange) {
|
|
38
|
-
onChange(
|
|
125
|
+
onChange(newValue);
|
|
39
126
|
}
|
|
40
|
-
}, [onChange]);
|
|
127
|
+
}, [handleControlFromSlider, interval, onChange]);
|
|
128
|
+
const fromSliderThumbPosition = (0, _react.useMemo)(() => {
|
|
129
|
+
if (fromSliderRef.current) {
|
|
130
|
+
return (fromValue - minValue) / (maxValue - minValue) * (fromSliderRef.current.offsetWidth - 20);
|
|
131
|
+
}
|
|
132
|
+
return 0;
|
|
133
|
+
}, [fromValue, maxValue, minValue]);
|
|
134
|
+
const toSliderThumbPosition = (0, _react.useMemo)(() => {
|
|
135
|
+
if (toSliderRef.current) {
|
|
136
|
+
return (toValue - minValue) / (maxValue - minValue) * (toSliderRef.current.offsetWidth - 20);
|
|
137
|
+
}
|
|
138
|
+
return 0;
|
|
139
|
+
}, [toValue, maxValue, minValue]);
|
|
41
140
|
return (0, _react.useMemo)(() => /*#__PURE__*/_react.default.createElement(_Slider.StyledSlider, null, /*#__PURE__*/_react.default.createElement(_Slider.StyledSliderInput, {
|
|
141
|
+
ref: fromSliderRef,
|
|
142
|
+
isInterval: !!interval,
|
|
42
143
|
type: "range",
|
|
43
|
-
value:
|
|
144
|
+
value: fromValue,
|
|
145
|
+
step: steps,
|
|
44
146
|
max: maxValue,
|
|
45
147
|
min: minValue,
|
|
46
148
|
onChange: handleInputChange
|
|
47
|
-
})
|
|
149
|
+
}), /*#__PURE__*/_react.default.createElement(_Slider.StyledSliderThumb, {
|
|
150
|
+
position: fromSliderThumbPosition
|
|
151
|
+
}, shouldShowThumbLable && /*#__PURE__*/_react.default.createElement(_Slider.StyledSliderThumbLable, null, typeof thumbLableFormatter === 'function' ? thumbLableFormatter(fromValue) : fromValue)), interval && /*#__PURE__*/_react.default.createElement(_Slider.StyledSliderThumb, {
|
|
152
|
+
position: toSliderThumbPosition
|
|
153
|
+
}, shouldShowThumbLable && /*#__PURE__*/_react.default.createElement(_Slider.StyledSliderThumbLable, null, typeof thumbLableFormatter === 'function' ? thumbLableFormatter(toValue) : toValue)), interval && /*#__PURE__*/_react.default.createElement(_Slider.StyledSliderInput, {
|
|
154
|
+
ref: toSliderRef,
|
|
155
|
+
isInterval: !!interval,
|
|
156
|
+
type: "range",
|
|
157
|
+
value: toValue,
|
|
158
|
+
step: steps,
|
|
159
|
+
max: maxValue,
|
|
160
|
+
min: minValue,
|
|
161
|
+
onChange: handleControlToSlider
|
|
162
|
+
})), [steps, fromSliderThumbPosition, fromValue, handleControlToSlider, handleInputChange, interval, maxValue, minValue, shouldShowThumbLable, thumbLableFormatter, toSliderThumbPosition, toValue]);
|
|
48
163
|
};
|
|
49
164
|
Slider.displayName = 'Slider';
|
|
50
165
|
var _default = exports.default = Slider;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Slider.js","names":["_react","_interopRequireWildcard","require","_Slider","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","prototype","hasOwnProperty","call","i","set","Slider","_ref","maxValue","minValue","value","onChange","editedValue","setEditedValue","useState","useEffect","handleInputChange","useCallback","event","Number","target","useMemo","createElement","StyledSlider","StyledSliderInput","type","max","min","displayName","_default","exports"],"sources":["../../../src/components/slider/Slider.tsx"],"sourcesContent":["import React, { ChangeEvent, FC, useCallback, useEffect, useMemo, useState } from 'react';\nimport { StyledSlider, StyledSliderInput } from './Slider.styles';\n\nexport type SliderProps = {\n /**\n * The maximum value of the slider.\n */\n maxValue: number;\n /**\n * The minimum value of the slider.\n */\n minValue: number;\n /**\n * Function that will be executed when the value is changed.\n */\n onChange?: (value: number) => void;\n /**\n * the Value that the slider should have.\n */\n value?: number;\n};\n\nconst Slider: FC<SliderProps> = ({ maxValue, minValue, value, onChange }) => {\n const [editedValue, setEditedValue] = useState(0);\n\n /**\n * This function sets the value\n */\n useEffect(() => {\n if (typeof value !== 'number') {\n return;\n }\n\n if (value >= minValue && value <= maxValue) {\n setEditedValue(value);\n }\n }, [maxValue, minValue, value]);\n\n /**\n * This function updates the value\n */\n const handleInputChange = useCallback(\n (event: ChangeEvent<HTMLInputElement>) => {\n setEditedValue(Number(event.target.value));\n\n if (onChange) {\n onChange(Number(event.target.value));\n }\n },\n [onChange]\n );\n\n return useMemo(\n () => (\n <StyledSlider>\n <StyledSliderInput\n type=\"range\"\n value={editedValue}\n max={maxValue}\n min={minValue}\n onChange={handleInputChange}\n />\n </StyledSlider>\n ),\n [editedValue, handleInputChange, maxValue, minValue]\n );\n};\n\nSlider.displayName = 'Slider';\n\nexport default Slider;\n"],"mappings":";;;;;;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C,OAAA,GAEfe,MAAM"}
|
|
1
|
+
{"version":3,"file":"Slider.js","names":["_react","_interopRequireWildcard","require","_Slider","_slider","_styledComponents","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","prototype","hasOwnProperty","call","i","set","Slider","_ref","maxValue","minValue","value","onChange","interval","thumbLableFormatter","shouldShowThumbLable","steps","fromValue","setFromValue","useState","toValue","setToValue","fromSliderRef","useRef","toSliderRef","theme","useTheme","useEffect","handleControlFromSlider","useCallback","event","current","Number","target","from","to","undefined","fillSlider","toSlider","fromSlider","String","handleControlToSlider","handleInputChange","newValue","fromSliderThumbPosition","useMemo","offsetWidth","toSliderThumbPosition","createElement","StyledSlider","StyledSliderInput","ref","isInterval","type","step","max","min","StyledSliderThumb","position","StyledSliderThumbLable","displayName","_default","exports"],"sources":["../../../src/components/slider/Slider.tsx"],"sourcesContent":["import React, { ChangeEvent, FC, useCallback, useEffect, useMemo, useRef, useState } from 'react';\nimport {\n StyledSlider,\n StyledSliderInput,\n StyledSliderThumb,\n StyledSliderThumbLable,\n} from './Slider.styles';\nimport { fillSlider } from '../../utils/slider';\nimport { useTheme } from 'styled-components';\n\nexport interface SliderInterval {\n maxValue: number;\n minValue: number;\n}\n\nexport type SliderProps = {\n /**\n * The range that can be selected with two thumbs..\n */\n interval?: SliderInterval;\n /**\n * The maximum value of the slider.\n */\n maxValue: number;\n /**\n * The minimum value of the slider.\n */\n minValue: number;\n /**\n * Function that will be executed when the value is changed.\n */\n onChange?: (value?: number, interval?: SliderInterval) => void;\n /**\n * Whether the current value should be displayed inside the slider thumb.\n */\n shouldShowThumbLable?: boolean;\n /**\n * The steps of the slider.\n */\n steps?: number;\n /**\n * A function to format the thumb lable.\n */\n thumbLableFormatter?: (value: number) => string;\n /**\n * the Value that the slider should have.\n */\n value?: number;\n};\n\nconst Slider: FC<SliderProps> = ({\n maxValue,\n minValue,\n value,\n onChange,\n interval,\n thumbLableFormatter,\n shouldShowThumbLable = false,\n steps = 1,\n}) => {\n const [fromValue, setFromValue] = useState(0);\n const [toValue, setToValue] = useState(maxValue);\n\n const fromSliderRef = useRef<HTMLInputElement>(null);\n const toSliderRef = useRef<HTMLInputElement>(null);\n\n const theme = useTheme();\n\n /**\n * This function sets the value\n */\n useEffect(() => {\n if (typeof value !== 'number') {\n return;\n }\n\n if (value >= minValue && value <= maxValue) {\n setFromValue(value);\n }\n }, [maxValue, minValue, value]);\n\n useEffect(() => {\n if (fromValue > toValue) {\n setFromValue(toValue);\n }\n\n if (toValue < fromValue) {\n setToValue(fromValue);\n }\n }, [fromValue, toValue]);\n\n const handleControlFromSlider = useCallback(\n (event: ChangeEvent<HTMLInputElement>) => {\n if (!fromSliderRef.current || !toSliderRef.current) {\n return;\n }\n\n setFromValue(Number(event.target.value));\n\n const from = Number(fromSliderRef.current.value);\n const to = Number(toSliderRef.current.value);\n\n if (typeof onChange === 'function') {\n onChange(undefined, { maxValue: to, minValue: from });\n }\n\n fillSlider({\n toSlider: toSliderRef.current,\n fromSlider: fromSliderRef.current,\n theme,\n });\n\n if (from > to) {\n fromSliderRef.current.value = String(to);\n } else {\n fromSliderRef.current.value = String(from);\n }\n },\n [onChange, theme]\n );\n\n const handleControlToSlider = useCallback(\n (event: ChangeEvent<HTMLInputElement>) => {\n if (!fromSliderRef.current || !toSliderRef.current) {\n return;\n }\n\n setToValue(Number(event.target.value));\n\n const from = Number(fromSliderRef.current.value);\n const to = Number(toSliderRef.current.value);\n\n if (typeof onChange === 'function') {\n onChange(undefined, { maxValue: to, minValue: from });\n }\n\n fillSlider({\n toSlider: toSliderRef.current,\n fromSlider: fromSliderRef.current,\n theme,\n });\n\n if (from <= to) {\n toSliderRef.current.value = String(to);\n } else {\n toSliderRef.current.value = String(from);\n }\n },\n [onChange, theme]\n );\n\n useEffect(() => {\n if (!fromSliderRef.current || !toSliderRef.current || !interval) {\n return;\n }\n\n setFromValue(interval.minValue);\n setToValue(interval.maxValue);\n\n fromSliderRef.current.value = String(interval.minValue);\n toSliderRef.current.value = String(interval.maxValue);\n\n fillSlider({\n fromSlider: fromSliderRef.current,\n toSlider: toSliderRef.current,\n theme,\n });\n // Note: interval can´t be in the deps because of rerender\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [theme]);\n\n /**\n * This function updates the value\n */\n const handleInputChange = useCallback(\n (event: ChangeEvent<HTMLInputElement>) => {\n const newValue = Number(event.target.value);\n\n if (interval) {\n handleControlFromSlider(event);\n\n return;\n }\n\n setFromValue(newValue);\n\n if (onChange) {\n onChange(newValue);\n }\n },\n [handleControlFromSlider, interval, onChange]\n );\n\n const fromSliderThumbPosition = useMemo(() => {\n if (fromSliderRef.current) {\n return (\n ((fromValue - minValue) / (maxValue - minValue)) *\n (fromSliderRef.current.offsetWidth - 20)\n );\n }\n return 0;\n }, [fromValue, maxValue, minValue]);\n\n const toSliderThumbPosition = useMemo(() => {\n if (toSliderRef.current) {\n return (\n ((toValue - minValue) / (maxValue - minValue)) *\n (toSliderRef.current.offsetWidth - 20)\n );\n }\n return 0;\n }, [toValue, maxValue, minValue]);\n\n return useMemo(\n () => (\n <StyledSlider>\n <StyledSliderInput\n ref={fromSliderRef}\n isInterval={!!interval}\n type=\"range\"\n value={fromValue}\n step={steps}\n max={maxValue}\n min={minValue}\n onChange={handleInputChange}\n />\n <StyledSliderThumb position={fromSliderThumbPosition}>\n {shouldShowThumbLable && (\n <StyledSliderThumbLable>\n {typeof thumbLableFormatter === 'function'\n ? thumbLableFormatter(fromValue)\n : fromValue}\n </StyledSliderThumbLable>\n )}\n </StyledSliderThumb>\n {interval && (\n <StyledSliderThumb position={toSliderThumbPosition}>\n {shouldShowThumbLable && (\n <StyledSliderThumbLable>\n {typeof thumbLableFormatter === 'function'\n ? thumbLableFormatter(toValue)\n : toValue}\n </StyledSliderThumbLable>\n )}\n </StyledSliderThumb>\n )}\n {interval && (\n <StyledSliderInput\n ref={toSliderRef}\n isInterval={!!interval}\n type=\"range\"\n value={toValue}\n step={steps}\n max={maxValue}\n min={minValue}\n onChange={handleControlToSlider}\n />\n )}\n </StyledSlider>\n ),\n [\n steps,\n fromSliderThumbPosition,\n fromValue,\n handleControlToSlider,\n handleInputChange,\n interval,\n maxValue,\n minValue,\n shouldShowThumbLable,\n thumbLableFormatter,\n toSliderThumbPosition,\n toValue,\n ]\n );\n};\n\nSlider.displayName = 'Slider';\n\nexport default Slider;\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AAMA,IAAAE,OAAA,GAAAF,OAAA;AACA,IAAAG,iBAAA,GAAAH,OAAA;AAA6C,SAAAI,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,CAAA,WAAAA,CAAA,GAAAG,CAAA,GAAAD,CAAA,KAAAF,CAAA;AAAA,SAAAN,wBAAAM,CAAA,EAAAE,CAAA,SAAAA,CAAA,IAAAF,CAAA,IAAAA,CAAA,CAAAI,UAAA,SAAAJ,CAAA,eAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,WAAAK,OAAA,EAAAL,CAAA,QAAAG,CAAA,GAAAJ,wBAAA,CAAAG,CAAA,OAAAC,CAAA,IAAAA,CAAA,CAAAG,GAAA,CAAAN,CAAA,UAAAG,CAAA,CAAAI,GAAA,CAAAP,CAAA,OAAAQ,CAAA,KAAAC,SAAA,UAAAC,CAAA,GAAAC,MAAA,CAAAC,cAAA,IAAAD,MAAA,CAAAE,wBAAA,WAAAC,CAAA,IAAAd,CAAA,oBAAAc,CAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAjB,CAAA,EAAAc,CAAA,SAAAI,CAAA,GAAAR,CAAA,GAAAC,MAAA,CAAAE,wBAAA,CAAAb,CAAA,EAAAc,CAAA,UAAAI,CAAA,K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,QAAQ,EAAE6B;EAAsB,CACnC,CAEK,CACjB,EACD,CACIzB,KAAK,EACL4B,uBAAuB,EACvB3B,SAAS,EACTwB,qBAAqB,EACrBC,iBAAiB,EACjB7B,QAAQ,EACRJ,QAAQ,EACRC,QAAQ,EACRK,oBAAoB,EACpBD,mBAAmB,EACnBiC,qBAAqB,EACrB3B,OAAO,CAEf,CAAC;AACL,CAAC;AAEDb,MAAM,CAACqD,WAAW,GAAG,QAAQ;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAAtE,OAAA,GAEfe,MAAM"}
|
|
@@ -5,6 +5,12 @@ type StyledSliderInputProps = WithTheme<{
|
|
|
5
5
|
min: number;
|
|
6
6
|
max: number;
|
|
7
7
|
value: number;
|
|
8
|
+
isInterval: boolean;
|
|
8
9
|
}>;
|
|
9
10
|
export declare const StyledSliderInput: import("styled-components").IStyledComponent<"web", import("styled-components/dist/types").Substitute<import("react").DetailedHTMLProps<import("react").InputHTMLAttributes<HTMLInputElement>, HTMLInputElement>, StyledSliderInputProps>>;
|
|
11
|
+
type StyledSliderThumbProps = WithTheme<{
|
|
12
|
+
position: number;
|
|
13
|
+
}>;
|
|
14
|
+
export declare const StyledSliderThumb: import("styled-components").IStyledComponent<"web", import("styled-components/dist/types").Substitute<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, StyledSliderThumbProps>>;
|
|
15
|
+
export declare const StyledSliderThumbLable: import("styled-components").IStyledComponent<"web", import("styled-components/dist/types").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>, never>>;
|
|
10
16
|
export {};
|
|
@@ -3,26 +3,48 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.StyledSliderInput = exports.StyledSlider = void 0;
|
|
7
|
-
var _styledComponents =
|
|
8
|
-
function
|
|
6
|
+
exports.StyledSliderThumbLable = exports.StyledSliderThumb = exports.StyledSliderInput = exports.StyledSlider = void 0;
|
|
7
|
+
var _styledComponents = _interopRequireWildcard(require("styled-components"));
|
|
8
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
9
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
9
10
|
const StyledSlider = exports.StyledSlider = _styledComponents.default.div`
|
|
10
11
|
width: 100%;
|
|
12
|
+
height: 30px;
|
|
11
13
|
cursor: pointer;
|
|
14
|
+
position: relative;
|
|
15
|
+
display: flex;
|
|
16
|
+
align-items: center;
|
|
12
17
|
`;
|
|
13
18
|
const StyledSliderInput = exports.StyledSliderInput = _styledComponents.default.input`
|
|
19
|
+
position: absolute;
|
|
14
20
|
width: 100%;
|
|
15
21
|
border-radius: 100px;
|
|
16
22
|
-webkit-appearance: none;
|
|
17
23
|
height: 10px;
|
|
18
|
-
|
|
24
|
+
outline: none;
|
|
25
|
+
//opacity: 0.7;
|
|
26
|
+
//-webkit-transition: 0.2s;
|
|
27
|
+
//transition: opacity 0.2s;
|
|
28
|
+
cursor: pointer !important;
|
|
29
|
+
z-index: 2;
|
|
30
|
+
appearance: none;
|
|
31
|
+
pointer-events: ${_ref => {
|
|
19
32
|
let {
|
|
33
|
+
isInterval
|
|
34
|
+
} = _ref;
|
|
35
|
+
return isInterval ? 'none' : 'all';
|
|
36
|
+
}};
|
|
37
|
+
|
|
38
|
+
${_ref2 => {
|
|
39
|
+
let {
|
|
40
|
+
isInterval,
|
|
20
41
|
theme,
|
|
21
42
|
min,
|
|
22
43
|
max,
|
|
23
44
|
value
|
|
24
|
-
} =
|
|
25
|
-
return `
|
|
45
|
+
} = _ref2;
|
|
46
|
+
return !isInterval && (0, _styledComponents.css)`
|
|
47
|
+
background: ${`linear-gradient(
|
|
26
48
|
to right,
|
|
27
49
|
${theme['409'] ?? ''} 0%,
|
|
28
50
|
${theme['409'] ?? ''}
|
|
@@ -30,14 +52,9 @@ const StyledSliderInput = exports.StyledSliderInput = _styledComponents.default.
|
|
|
30
52
|
${theme['403'] ?? ''}
|
|
31
53
|
${(value - min) / (max - min) * 100}%,
|
|
32
54
|
${theme['403'] ?? ''}
|
|
33
|
-
)
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
outline: none;
|
|
37
|
-
opacity: 0.7;
|
|
38
|
-
-webkit-transition: 0.2s;
|
|
39
|
-
transition: opacity 0.2s;
|
|
40
|
-
cursor: pointer !important;
|
|
55
|
+
)`};
|
|
56
|
+
`;
|
|
57
|
+
}}
|
|
41
58
|
|
|
42
59
|
// Slider thumb for chrome
|
|
43
60
|
&::-webkit-slider-thumb {
|
|
@@ -45,30 +62,48 @@ const StyledSliderInput = exports.StyledSliderInput = _styledComponents.default.
|
|
|
45
62
|
appearance: none;
|
|
46
63
|
width: 20px;
|
|
47
64
|
height: 20px;
|
|
48
|
-
background-color: ${_ref2 => {
|
|
49
|
-
let {
|
|
50
|
-
theme
|
|
51
|
-
} = _ref2;
|
|
52
|
-
return theme['100'];
|
|
53
|
-
}};
|
|
54
65
|
cursor: pointer;
|
|
55
|
-
|
|
56
|
-
|
|
66
|
+
pointer-events: all;
|
|
67
|
+
position: relative;
|
|
57
68
|
}
|
|
58
69
|
|
|
59
70
|
// slider thumb for firefox
|
|
60
71
|
&::-moz-range-thumb {
|
|
61
72
|
width: 20px;
|
|
62
73
|
height: 20px;
|
|
63
|
-
|
|
74
|
+
cursor: pointer;
|
|
75
|
+
pointer-events: all;
|
|
76
|
+
position: relative;
|
|
77
|
+
}
|
|
78
|
+
`;
|
|
79
|
+
const StyledSliderThumb = exports.StyledSliderThumb = _styledComponents.default.div`
|
|
80
|
+
min-width: 20px;
|
|
81
|
+
width: fit-content;
|
|
82
|
+
height: 20px;
|
|
83
|
+
background-color: ${_ref3 => {
|
|
64
84
|
let {
|
|
65
85
|
theme
|
|
66
86
|
} = _ref3;
|
|
67
87
|
return theme['100'];
|
|
68
88
|
}};
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
89
|
+
cursor: pointer;
|
|
90
|
+
border-radius: 100px;
|
|
91
|
+
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.4);
|
|
92
|
+
pointer-events: none;
|
|
93
|
+
z-index: 3;
|
|
94
|
+
left: ${_ref4 => {
|
|
95
|
+
let {
|
|
96
|
+
position
|
|
97
|
+
} = _ref4;
|
|
98
|
+
return position;
|
|
99
|
+
}}px;
|
|
100
|
+
position: absolute;
|
|
101
|
+
display: flex;
|
|
102
|
+
align-items: center;
|
|
103
|
+
justify-content: center;
|
|
104
|
+
padding: 0 8px;
|
|
105
|
+
`;
|
|
106
|
+
const StyledSliderThumbLable = exports.StyledSliderThumbLable = _styledComponents.default.span`
|
|
107
|
+
pointer-events: none;
|
|
73
108
|
`;
|
|
74
109
|
//# sourceMappingURL=Slider.styles.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Slider.styles.js","names":["_styledComponents","
|
|
1
|
+
{"version":3,"file":"Slider.styles.js","names":["_styledComponents","_interopRequireWildcard","require","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","prototype","hasOwnProperty","call","i","set","StyledSlider","exports","styled","div","StyledSliderInput","input","_ref","isInterval","_ref2","theme","min","max","value","css","StyledSliderThumb","_ref3","_ref4","position","StyledSliderThumbLable","span"],"sources":["../../../src/components/slider/Slider.styles.ts"],"sourcesContent":["import styled, { css } from 'styled-components';\nimport type { WithTheme } from '../color-scheme-provider/ColorSchemeProvider';\n\nexport const StyledSlider = styled.div`\n width: 100%;\n height: 30px;\n cursor: pointer;\n position: relative;\n display: flex;\n align-items: center;\n`;\n\ntype StyledSliderInputProps = WithTheme<{\n min: number;\n max: number;\n value: number;\n isInterval: boolean;\n}>;\n\nexport const StyledSliderInput = styled.input<StyledSliderInputProps>`\n position: absolute;\n width: 100%;\n border-radius: 100px;\n -webkit-appearance: none;\n height: 10px;\n outline: none;\n //opacity: 0.7;\n //-webkit-transition: 0.2s;\n //transition: opacity 0.2s;\n cursor: pointer !important;\n z-index: 2;\n appearance: none;\n pointer-events: ${({ isInterval }) => (isInterval ? 'none' : 'all')};\n\n ${({ isInterval, theme, min, max, value }: StyledSliderInputProps) =>\n !isInterval &&\n css`\n background: ${`linear-gradient(\n to right,\n ${theme['409'] ?? ''} 0%,\n ${theme['409'] ?? ''}\n ${((value - min) / (max - min)) * 100}%,\n ${theme['403'] ?? ''}\n ${((value - min) / (max - min)) * 100}%,\n ${theme['403'] ?? ''}\n )`};\n `}\n\n // Slider thumb for chrome\n &::-webkit-slider-thumb {\n -webkit-appearance: none;\n appearance: none;\n width: 20px;\n height: 20px;\n cursor: pointer;\n pointer-events: all;\n position: relative;\n }\n\n // slider thumb for firefox\n &::-moz-range-thumb {\n width: 20px;\n height: 20px;\n cursor: pointer;\n pointer-events: all;\n position: relative;\n }\n`;\n\ntype StyledSliderThumbProps = WithTheme<{ position: number }>;\n\nexport const StyledSliderThumb = styled.div<StyledSliderThumbProps>`\n min-width: 20px;\n width: fit-content;\n height: 20px;\n background-color: ${({ theme }: StyledSliderThumbProps) => theme['100']};\n cursor: pointer;\n border-radius: 100px;\n box-shadow: 0 2px 4px rgba(0, 0, 0, 0.4);\n pointer-events: none;\n z-index: 3;\n left: ${({ position }) => position}px;\n position: absolute;\n display: flex;\n align-items: center;\n justify-content: center;\n padding: 0 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KAAK,CAAC,KAAK,CAAC;AAAA,CAAC;AAC5E;AACA;AACA;AACA;AACA;AACA,YAAYO,KAAA;EAAA,IAAC;IAAEC;EAAS,CAAC,GAAAD,KAAA;EAAA,OAAKC,QAAQ;AAAA,CAAC;AACvC;AACA;AACA;AACA;AACA;AACA,CAAC;AAEM,MAAMC,sBAAsB,GAAAjB,OAAA,CAAAiB,sBAAA,GAAGhB,yBAAM,CAACiB,IAAK;AAClD;AACA,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Theme } from '../components/color-scheme-provider/ColorSchemeProvider';
|
|
2
|
+
export interface FillSlider {
|
|
3
|
+
fromSlider: HTMLInputElement;
|
|
4
|
+
toSlider: HTMLInputElement;
|
|
5
|
+
theme: Theme;
|
|
6
|
+
}
|
|
7
|
+
export declare const fillSlider: ({ fromSlider, toSlider, theme }: FillSlider) => void;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.fillSlider = void 0;
|
|
7
|
+
const fillSlider = _ref => {
|
|
8
|
+
let {
|
|
9
|
+
fromSlider,
|
|
10
|
+
toSlider,
|
|
11
|
+
theme
|
|
12
|
+
} = _ref;
|
|
13
|
+
const rangeDistance = Number(toSlider.max) - Number(toSlider.min);
|
|
14
|
+
const fromPosition = Number(fromSlider.value) - Number(toSlider.min);
|
|
15
|
+
const toPosition = Number(toSlider.value) - Number(toSlider.min);
|
|
16
|
+
const backgroundColor = theme['403'];
|
|
17
|
+
const trackColor = theme['409'];
|
|
18
|
+
if (!backgroundColor || !trackColor) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
const gradient = `linear-gradient(
|
|
22
|
+
to right,
|
|
23
|
+
${backgroundColor} 0%,
|
|
24
|
+
${backgroundColor} ${fromPosition / rangeDistance * 100}%,
|
|
25
|
+
${trackColor} ${fromPosition / rangeDistance * 100}%,
|
|
26
|
+
${trackColor} ${toPosition / rangeDistance * 100}%,
|
|
27
|
+
${backgroundColor} ${toPosition / rangeDistance * 100}%,
|
|
28
|
+
${backgroundColor} 100%)`;
|
|
29
|
+
|
|
30
|
+
// Apply the gradient to the appropriate slider
|
|
31
|
+
toSlider.style.background = gradient;
|
|
32
|
+
fromSlider.style.background = gradient;
|
|
33
|
+
};
|
|
34
|
+
exports.fillSlider = fillSlider;
|
|
35
|
+
//# sourceMappingURL=slider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"slider.js","names":["fillSlider","_ref","fromSlider","toSlider","theme","rangeDistance","Number","max","min","fromPosition","value","toPosition","backgroundColor","trackColor","gradient","style","background","exports"],"sources":["../../src/utils/slider.ts"],"sourcesContent":["import type { Theme } from '../components/color-scheme-provider/ColorSchemeProvider';\n\nexport interface FillSlider {\n fromSlider: HTMLInputElement;\n toSlider: HTMLInputElement;\n theme: Theme;\n}\n\nexport const fillSlider = ({ fromSlider, toSlider, theme }: FillSlider) => {\n const rangeDistance = Number(toSlider.max) - Number(toSlider.min);\n const fromPosition = Number(fromSlider.value) - Number(toSlider.min);\n const toPosition = Number(toSlider.value) - Number(toSlider.min);\n\n const backgroundColor = theme['403'];\n const trackColor = theme['409'];\n\n if (!backgroundColor || !trackColor) {\n return;\n }\n\n const gradient = `linear-gradient(\n to right,\n ${backgroundColor} 0%,\n ${backgroundColor} ${(fromPosition / rangeDistance) * 100}%,\n ${trackColor} ${(fromPosition / rangeDistance) * 100}%,\n ${trackColor} ${(toPosition / rangeDistance) * 100}%,\n ${backgroundColor} ${(toPosition / rangeDistance) * 100}%,\n ${backgroundColor} 100%)`;\n\n // Apply the gradient to the appropriate slider\n toSlider.style.background = gradient;\n fromSlider.style.background = gradient;\n};\n"],"mappings":";;;;;;AAQO,MAAMA,UAAU,GAAGC,IAAA,IAAiD;EAAA,IAAhD;IAAEC,UAAU;IAAEC,QAAQ;IAAEC;EAAkB,CAAC,GAAAH,IAAA;EAClE,MAAMI,aAAa,GAAGC,MAAM,CAACH,QAAQ,CAACI,GAAG,CAAC,GAAGD,MAAM,CAACH,QAAQ,CAACK,GAAG,CAAC;EACjE,MAAMC,YAAY,GAAGH,MAAM,CAACJ,UAAU,CAACQ,KAAK,CAAC,GAAGJ,MAAM,CAACH,QAAQ,CAACK,GAAG,CAAC;EACpE,MAAMG,UAAU,GAAGL,MAAM,CAACH,QAAQ,CAACO,KAAK,CAAC,GAAGJ,MAAM,CAACH,QAAQ,CAACK,GAAG,CAAC;EAEhE,MAAMI,eAAe,GAAGR,KAAK,CAAC,KAAK,CAAC;EACpC,MAAMS,UAAU,GAAGT,KAAK,CAAC,KAAK,CAAC;EAE/B,IAAI,CAACQ,eAAe,IAAI,CAACC,UAAU,EAAE;IACjC;EACJ;EAEA,MAAMC,QAAQ,GAAI;AACtB;AACA,QAAQF,eAAgB;AACxB,QAAQA,eAAgB,IAAIH,YAAY,GAAGJ,aAAa,GAAI,GAAI;AAChE,QAAQQ,UAAW,IAAIJ,YAAY,GAAGJ,aAAa,GAAI,GAAI;AAC3D,QAAQQ,UAAW,IAAIF,UAAU,GAAGN,aAAa,GAAI,GAAI;AACzD,QAAQO,eAAgB,IAAID,UAAU,GAAGN,aAAa,GAAI,GAAI;AAC9D,QAAQO,eAAgB,QAAO;;EAE3B;EACAT,QAAQ,CAACY,KAAK,CAACC,UAAU,GAAGF,QAAQ;EACpCZ,UAAU,CAACa,KAAK,CAACC,UAAU,GAAGF,QAAQ;AAC1C,CAAC;AAACG,OAAA,CAAAjB,UAAA,GAAAA,UAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chayns-components/core",
|
|
3
|
-
"version": "5.0.0-beta.
|
|
3
|
+
"version": "5.0.0-beta.408",
|
|
4
4
|
"description": "A set of beautiful React components for developing your own applications with chayns.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"chayns",
|
|
@@ -70,5 +70,5 @@
|
|
|
70
70
|
"publishConfig": {
|
|
71
71
|
"access": "public"
|
|
72
72
|
},
|
|
73
|
-
"gitHead": "
|
|
73
|
+
"gitHead": "a3947cd337d1bd98fafe1d810bfaa1693c7ade57"
|
|
74
74
|
}
|