-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…not-accept-inline-editing Feature/#413 time picker does not accept inline editing
- Loading branch information
Showing
10 changed files
with
222 additions
and
100 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 0 additions & 86 deletions
86
src/common/components/mock-components/front-components/timepickerinput-shape.tsx
This file was deleted.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
src/common/components/mock-components/front-components/timepickerinput/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './timepickerinput-shape.tsx'; |
33 changes: 33 additions & 0 deletions
33
...onents/mock-components/front-components/timepickerinput/timepickerinput-shape.business.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
const MAX_DIGITS = 2; | ||
const MAX_HOURS = '23'; | ||
const MAX_MINUTES = '59'; | ||
const HOUR_MASK = 'hh'; | ||
const MINUTES_MASK = 'mm'; | ||
|
||
export const splitCSVContent = (csvContent: string): string[] => { | ||
const splitedCsvContent = csvContent | ||
.trim() | ||
.split(/[:|,]/) | ||
.map(el => el.trim()); | ||
return splitedCsvContent; | ||
}; | ||
|
||
export const setTime = (csvData: string[]) => { | ||
let [hour, minutes] = csvData; | ||
if (csvData.length < 2) { | ||
return true; | ||
} | ||
if (csvData[0] !== HOUR_MASK || csvData[1] !== MINUTES_MASK) { | ||
if ( | ||
csvData.length > MAX_DIGITS || | ||
hour.length !== MAX_DIGITS || | ||
hour === '' || | ||
hour > MAX_HOURS || | ||
minutes.length !== MAX_DIGITS || | ||
minutes === '' || | ||
minutes > MAX_MINUTES | ||
) { | ||
return true; | ||
} | ||
} | ||
}; |
148 changes: 148 additions & 0 deletions
148
...mon/components/mock-components/front-components/timepickerinput/timepickerinput-shape.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
import { ShapeSizeRestrictions, ShapeType } from '@/core/model'; | ||
import { forwardRef } from 'react'; | ||
import { ShapeProps } from '../../shape.model'; | ||
import { fitSizeToShapeSizeRestrictions } from '@/common/utils/shapes/shape-restrictions'; | ||
import { Group, Rect, Text, Image } from 'react-konva'; | ||
import { BASIC_SHAPE } from '../shape.const'; | ||
import { useShapeProps } from '../../../shapes/use-shape-props.hook'; | ||
import { useGroupShapeProps } from '../../mock-components.utils'; | ||
import { splitCSVContent, setTime } from './timepickerinput-shape.business'; | ||
|
||
import clockIconSrc from '/icons/clock.svg'; | ||
|
||
const timepickerInputShapeRestrictions: ShapeSizeRestrictions = { | ||
minWidth: 100, | ||
minHeight: 50, | ||
maxWidth: -1, | ||
maxHeight: 50, | ||
defaultWidth: 220, | ||
defaultHeight: 50, | ||
}; | ||
|
||
const shapeType: ShapeType = 'timepickerinput'; | ||
|
||
export const getTimepickerInputShapeSizeRestrictions = | ||
(): ShapeSizeRestrictions => timepickerInputShapeRestrictions; | ||
|
||
export const TimepickerInputShape = forwardRef<any, ShapeProps>( | ||
(props, ref) => { | ||
const { | ||
x, | ||
y, | ||
width, | ||
height, | ||
id, | ||
text, | ||
onSelected, | ||
otherProps, | ||
...shapeProps | ||
} = props; | ||
|
||
const restrictedSize = fitSizeToShapeSizeRestrictions( | ||
timepickerInputShapeRestrictions, | ||
width, | ||
height | ||
); | ||
const { width: restrictedWidth, height: restrictedHeight } = restrictedSize; | ||
|
||
const { stroke, strokeStyle, fill, borderRadius } = useShapeProps( | ||
otherProps, | ||
BASIC_SHAPE | ||
); | ||
|
||
const commonGroupProps = useGroupShapeProps( | ||
props, | ||
restrictedSize, | ||
shapeType, | ||
ref | ||
); | ||
|
||
const csvData = splitCSVContent(text); | ||
let isError = setTime(csvData); | ||
|
||
const iconWidth = 25; | ||
const availableWidth = restrictedWidth - iconWidth - 20; | ||
const fontSize = Math.min( | ||
availableWidth * 0.2, | ||
restrictedHeight * 0.35, | ||
20 | ||
); | ||
const labelFontSize = Math.min(restrictedHeight * 0.3, 12); | ||
|
||
const clockIcon = new window.Image(); | ||
clockIcon.src = clockIconSrc; | ||
|
||
return ( | ||
<Group {...commonGroupProps} {...shapeProps}> | ||
{/* External Rectangle */} | ||
<Rect | ||
x={0} | ||
y={0} | ||
width={restrictedWidth} | ||
height={restrictedHeight} | ||
cornerRadius={borderRadius} | ||
stroke={stroke} | ||
dash={strokeStyle} | ||
strokeWidth={BASIC_SHAPE.DEFAULT_STROKE_WIDTH} | ||
fill={fill} | ||
/> | ||
{/* Background of Time Label */} | ||
<Rect | ||
x={10} | ||
y={-5} | ||
width={labelFontSize + 20} | ||
height={labelFontSize} | ||
cornerRadius={borderRadius} | ||
strokeWidth={BASIC_SHAPE.DEFAULT_STROKE_WIDTH} | ||
fill="white" | ||
/> | ||
{/* Label "Time" */} | ||
<Text | ||
text="Time" | ||
x={13} | ||
y={-5} | ||
fontFamily={BASIC_SHAPE.DEFAULT_FONT_FAMILY} | ||
fontSize={BASIC_SHAPE.DEFAULT_FONT_SIZE - 4} | ||
fill={stroke} | ||
align="center" | ||
color={stroke} | ||
/> | ||
{/* Main Text */} | ||
<Text | ||
text={text} | ||
x={10} | ||
y={(restrictedHeight - fontSize) / 2 + 2} | ||
width={availableWidth} | ||
fontFamily={BASIC_SHAPE.DEFAULT_FONT_FAMILY} | ||
fontSize={BASIC_SHAPE.DEFAULT_FONT_SIZE} | ||
lineHeight={BASIC_SHAPE.DEFAULT_LINE_HEIGHT} | ||
align="left" | ||
ellipsis={true} | ||
wrap="none" | ||
/> | ||
{/* Error Text */} | ||
{isError && ( | ||
<Text | ||
text="Error, valid format hh:mm" | ||
x={10} | ||
y={35} | ||
fontFamily={BASIC_SHAPE.DEFAULT_FONT_FAMILY} | ||
fontSize={10} | ||
fill="red" | ||
align="center" | ||
color={stroke} | ||
/> | ||
)} | ||
|
||
{/* Clock Icon */} | ||
<Image | ||
image={clockIcon} | ||
x={restrictedWidth - iconWidth - 5} | ||
y={(restrictedHeight - 20) / 2} | ||
width={20} | ||
height={20} | ||
/> | ||
</Group> | ||
); | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters