-
-
Notifications
You must be signed in to change notification settings - Fork 767
/
Copy pathfeature-matrix.tsx
166 lines (149 loc) · 3.82 KB
/
feature-matrix.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
import { MAX_CONTENT_WIDTH } from "@/style";
import React, { Fragment, ReactElement } from "react";
import styled from "styled-components";
import { Icon } from "@/components/sprites";
import { IconContainer } from "./icon-container";
// Icons
import CheckIconSvg from "@/images/icons/check.svg";
import MinusIconSvg from "@/images/icons/minus.svg";
export interface FeatureMatrixProps {
readonly plans: readonly string[];
readonly featureGroups: readonly FeatureGroup[];
}
export function FeatureMatrix({
plans,
featureGroups,
}: FeatureMatrixProps): ReactElement {
return (
<FeatureMatrixContainer $maxColumns={plans.length > 4 ? 4 : plans.length}>
<PlanDescription>Plans</PlanDescription>
{plans.map((title) => (
<PlanName key={`plan-${title}`}>{title}</PlanName>
))}
{featureGroups.map((props, index) => (
<FeatureGroup
key={`feature-group-${index}`}
columns={plans.length + 1}
{...props}
/>
))}
</FeatureMatrixContainer>
);
}
export interface FeatureGroup {
readonly title: string;
readonly features: readonly Feature[];
}
export interface Feature {
readonly title: string;
readonly description?: string;
readonly values: readonly (boolean | string)[];
}
interface FeatureGroupProps extends FeatureGroup {
readonly columns: number;
}
function FeatureGroup({
title,
features,
columns,
}: FeatureGroupProps): ReactElement {
function renderValue(value: boolean | string): ReactElement {
switch (value) {
case true:
return (
<IconContainer $size={14}>
<Icon {...CheckIconSvg} />
</IconContainer>
);
case false:
return (
<IconContainer $size={14}>
<Icon {...MinusIconSvg} />
</IconContainer>
);
default:
return <>{value}</>;
}
}
return (
<>
<FeatureGroupTitle $columns={columns}>{title}</FeatureGroupTitle>
{features.map((feature, index) => (
<Fragment key={`feature-${title}-${index}`}>
<FeatureDescription>{feature.title}</FeatureDescription>
{feature.values.map((value, valueIndex) => (
<Feature key={`feature-${title}-${index}-value-${valueIndex}`}>
{renderValue(value)}
</Feature>
))}
</Fragment>
))}
</>
);
}
const FeatureMatrixContainer = styled.div<{
readonly $maxColumns: number;
}>`
display: grid;
grid-template-columns: 220px repeat(
${({ $maxColumns }) => $maxColumns},
minmax(160px, 300px)
);
row-gap: 48px;
border: 1px solid #37353f;
border-radius: var(--box-border-radius);
width: ${MAX_CONTENT_WIDTH};
padding: 38px 44px 44px;
backdrop-filter: blur(2px);
background-image: radial-gradient(
ellipse at bottom,
#15113599 0%,
#0c0c2399 40%
);
box-shadow: 0 0 120px 60px #fdfdfd12;
overflow: visible;
`;
const PlanDescription = styled.div`
display: flex;
flex-direction: column;
align-items: flex-start;
justify-content: center;
overflow: visible;
`;
const PlanName = styled.div`
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
overflow: visible;
`;
const FeatureGroupTitle = styled.div.attrs({
className: "text-2",
})<{
readonly $columns: number;
}>`
display: flex;
flex-direction: column;
align-items: flex-start;
justify-content: center;
grid-column: 1 / ${({ $columns }) => $columns + 1};
overflow: visible;
`;
const FeatureDescription = styled.div.attrs({
className: "text-2",
})`
display: flex;
flex-direction: column;
align-items: flex-start;
justify-content: center;
overflow: visible;
`;
const Feature = styled.div.attrs({
className: "text-2",
})`
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
overflow: visible;
`;