Skip to content

Commit e8b6255

Browse files
author
유동식
authored
Merge pull request #640 from nhn/feat/column/event-blocks/2.0
feat: [v2] add column events layout
2 parents 152c7f8 + fea6d5d commit e8b6255

36 files changed

+1032
-186
lines changed

package-lock.json

+21-65
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
"@storybook/addon-links": "^5.3.13",
4343
"@storybook/addons": "^5.3.13",
4444
"@storybook/preact": "^5.3.13",
45+
"@types/chance": "^1.1.0",
4546
"@types/classnames": "^2.2.9",
4647
"@types/jasmine": "^2.8.16",
4748
"@types/karma-fixture": "^0.2.5",
@@ -50,6 +51,7 @@
5051
"@typescript-eslint/eslint-plugin": "^2.3.0",
5152
"@typescript-eslint/parser": "^2.3.0",
5253
"babel-loader": "^8.0.6",
54+
"chance": "^1.1.6",
5355
"clean-webpack-plugin": "^3.0.0",
5456
"css-loader": "^3.2.0",
5557
"eslint": "^6.4.0",
@@ -138,7 +140,7 @@
138140
"build-storybook": "build-storybook"
139141
},
140142
"dependencies": {
141-
"@toast-ui/date": "0.0.2",
143+
"@toast-ui/date": "0.0.3",
142144
"classnames": "^2.2.6",
143145
"preact": "^10.3.2",
144146
"preact-markup": "^2.0.0",

src/sass/events/background.scss

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
.event-background {
2-
display: inline-block;
2+
position: absolute;
33
}

src/sass/events/index.scss

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
@import './background.scss';
2+
@import './time.scss';

src/sass/events/time.scss

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
.event-time {
2+
position: absolute;
3+
overflow: hidden;
4+
5+
cursor: pointer;
6+
7+
.travel-time,
8+
.event-time-content {
9+
overflow: hidden;
10+
padding: 1px 0 0 3px;
11+
font-size: 12px;
12+
}
13+
}
14+
15+
.resize-handler-x {
16+
position: absolute;
17+
right: 0;
18+
bottom: 1px;
19+
left: 0;
20+
height: 5px;
21+
text-align: center;
22+
color: #fff;
23+
cursor: row-resize;
24+
25+
background: url(./image/handler-x.png) no-repeat center center;
26+
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

src/sass/timegrid/column.scss

+8-4
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,6 @@
1919
}
2020
}
2121

22-
.event-background {
23-
position: absolute;
24-
}
25-
2622
.guide-creation {
2723
position: absolute;
2824
right: 10px;
@@ -42,4 +38,12 @@
4238
}
4339
}
4440
}
41+
42+
.events {
43+
position: absolute;
44+
left: 0;
45+
top: 0;
46+
right: 0;
47+
bottom: 0;
48+
}
4549
}

src/ts/components/events/time.tsx

-18
This file was deleted.
+116
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
import { h } from 'preact';
2+
import { Template } from '@src/components/template';
3+
import { cls } from '@src/util/cssHelper';
4+
import ScheduleViewModel from '@src/model/scheduleViewModel';
5+
import { toPercent } from '@src/util/units';
6+
7+
const classNames = {
8+
time: cls('event-time'),
9+
content: cls('event-time-content'),
10+
travelTime: cls('travel-time'),
11+
resizeHandleX: cls('resize-handler-x')
12+
};
13+
14+
interface Props {
15+
viewModel: ScheduleViewModel;
16+
}
17+
18+
function getStyles(viewModel: ScheduleViewModel) {
19+
const {
20+
top,
21+
left,
22+
height,
23+
width,
24+
model,
25+
goingDurationHeight,
26+
modelDurationHeight,
27+
comingDurationHeight,
28+
croppedStart,
29+
croppedEnd
30+
} = viewModel;
31+
// get theme values
32+
const travelBorderColor = 'white';
33+
const borderRadius = 2;
34+
const paddingLeft = 2;
35+
const defaultMarginBottom = 2;
36+
const marginLeft = left > 0 ? paddingLeft : 0;
37+
38+
const { color, bgColor, borderColor } = model;
39+
const containerStyle: Record<string, string | number> = {
40+
width: width >= 0 ? `calc(${toPercent(width)} - ${marginLeft}px)` : '',
41+
height: `calc(${toPercent(height)} - ${defaultMarginBottom}px)`,
42+
top: toPercent(top),
43+
left: toPercent(left),
44+
borderRadius,
45+
borderLeft: `3px solid ${borderColor}`,
46+
marginLeft,
47+
color,
48+
backgroundColor: bgColor
49+
};
50+
const goingDurationStyle = {
51+
height: toPercent(goingDurationHeight),
52+
borderBottom: `1px dashed ${travelBorderColor}`
53+
};
54+
const modelDurationStyle = {
55+
height: toPercent(modelDurationHeight)
56+
};
57+
const comingDurationStyle = {
58+
height: toPercent(comingDurationHeight),
59+
borderTop: `1px dashed ${travelBorderColor}`
60+
};
61+
62+
if (croppedStart) {
63+
containerStyle.borderTopLeftRadius = 0;
64+
containerStyle.borderTopRightRadius = 0;
65+
}
66+
67+
if (croppedEnd) {
68+
containerStyle.borderBottomLeftRadius = 0;
69+
containerStyle.borderBottomRightRadius = 0;
70+
}
71+
72+
return {
73+
containerStyle,
74+
goingDurationStyle,
75+
modelDurationStyle,
76+
comingDurationStyle
77+
};
78+
}
79+
80+
export function TimeEvent(props: Props) {
81+
const { viewModel } = props;
82+
const {
83+
model,
84+
goingDurationHeight,
85+
modelDurationHeight,
86+
comingDurationHeight,
87+
croppedEnd
88+
} = viewModel;
89+
const { isReadOnly } = model;
90+
const { containerStyle, goingDurationStyle, modelDurationStyle, comingDurationStyle } = getStyles(
91+
viewModel
92+
);
93+
94+
return (
95+
<div className={classNames.time} style={containerStyle}>
96+
{goingDurationHeight ? (
97+
<div className={classNames.travelTime} style={goingDurationStyle}>
98+
<Template template="goingDuration" model={model} />
99+
</div>
100+
) : null}
101+
{modelDurationHeight ? (
102+
<div className={classNames.content} style={modelDurationStyle}>
103+
<Template template="time" model={model} />
104+
</div>
105+
) : null}
106+
{comingDurationHeight ? (
107+
<div className={classNames.travelTime} style={comingDurationStyle}>
108+
<Template template="comingDuration" model={model} />
109+
</div>
110+
) : null}
111+
{!croppedEnd && !isReadOnly ? <div className={classNames.resizeHandleX} /> : null}
112+
</div>
113+
);
114+
}
115+
TimeEvent.displayName = 'TimeEvent';
116+
TimeEvent.defaultProps = {};

src/ts/components/template.tsx

+10-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { h } from 'preact';
22
import Markup from 'preact-markup';
33
import isString from 'tui-code-snippet/type/isString';
4+
import browser from 'tui-code-snippet/browser/browser';
45
import { identity } from '@src/util';
56
import { TemplateName } from '@src/template/default';
67
import ContextComponent from '@src/components/contextComponent';
@@ -21,10 +22,14 @@ export class Template extends ContextComponent<Props> {
2122
const templateFunc: Function = templates[template] || identity;
2223
const htmlOrVnode = templateFunc(model, h);
2324

24-
return isString(htmlOrVnode) ? (
25-
<Markup wrap={false} markup={htmlOrVnode} type="html" />
26-
) : (
27-
htmlOrVnode
28-
);
25+
if (isString(htmlOrVnode)) {
26+
if (browser.msie && browser.version === 9) {
27+
return <span dangerouslySetInnerHTML={{ __html: htmlOrVnode }} />;
28+
}
29+
30+
return <Markup wrap={false} markup={htmlOrVnode} type="html" />;
31+
}
32+
33+
return htmlOrVnode;
2934
}
3035
}

0 commit comments

Comments
 (0)