Skip to content

Commit 174e208

Browse files
authored
Merge pull request #1193 from grafana/staging
feat: add extensions checkbox and link (#1190)
2 parents f3ba068 + afe157f commit 174e208

File tree

5 files changed

+98
-77
lines changed

5 files changed

+98
-77
lines changed

src/components/shared/checkbox-field/checkbox-field.module.scss

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515

1616
&:before {
1717
content: '';
18-
display: block;
18+
display: inline-flex;
19+
justify-content: center;
1920
width: 24px;
2021
height: 24px;
2122
border: 1px solid $color-additional-1;

src/components/shared/extension-card/extension-card.module.scss

Lines changed: 37 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,14 @@
11
.wrapper {
22
position: relative;
3-
display: flex;
4-
align-items: flex-start;
5-
padding: 20px;
3+
padding: 16px 19px;
64
text-decoration: none;
75
color: $color-primary;
86
width: 100%;
7+
flex-grow: 1;
98
background: $color-tertiary;
9+
cursor: pointer;
1010

1111
&.withCheckbox {
12-
cursor: pointer;
13-
14-
& .name {
15-
padding-right: 25px;
16-
}
17-
1812
&.checked .name {
1913
color: $color-accent-primary;
2014
}
@@ -25,17 +19,21 @@
2519
color: $color-accent-primary;
2620
}
2721
}
22+
23+
@include xs-down {
24+
padding: 12px;
25+
}
2826
}
2927

3028
.checkbox {
3129
position: absolute;
32-
top: 20px;
33-
right: 20px;
34-
}
30+
top: 18px;
31+
right: 16px;
3532

36-
.checked {
37-
outline: 1px solid #7d64ff;
38-
box-shadow: 0px 1px 5px rgba(60, 60, 100, 0.05);
33+
@include xs-down {
34+
top: 12px;
35+
right: 12px;
36+
}
3937
}
4038

4139
.imageWrapper {
@@ -81,16 +79,13 @@
8179

8280
.tiers-wrapper {
8381
display: flex;
84-
flex-wrap: wrap;
85-
width: 100%;
8682
align-items: center;
8783
list-style-type: none;
8884
padding: 0;
89-
margin-top: 0;
90-
margin-bottom: 0px;
85+
margin: 0;
9186

9287
li + li {
93-
margin-left: 8px;
88+
margin-left: 6px;
9489

9590
&::before {
9691
content: '';
@@ -115,23 +110,6 @@
115110
margin-right: 8px;
116111
}
117112

118-
.logo-wrapper {
119-
margin-left: auto !important;
120-
max-height: 28px;
121-
//position: absolute;
122-
//top: 20px;
123-
//right: 20px;
124-
125-
&:before {
126-
content: none;
127-
}
128-
}
129-
130-
.logo {
131-
position: relative;
132-
max-height: inherit;
133-
}
134-
135113
.tier {
136114
position: relative;
137115
display: flex;
@@ -172,15 +150,23 @@
172150
}
173151

174152
.name-wrapper {
175-
margin-top: 10px;
153+
padding-right: 30px;
176154
text-align: left;
177155
}
178156

179157
.name {
158+
position: relative;
180159
font-size: $font-size-lg;
181160
line-height: $line-height-lg;
182161
font-weight: 700;
162+
text-decoration: none;
183163
transition: color 0.3s;
164+
color: $color-primary;
165+
cursor: pointer;
166+
167+
&:hover {
168+
color: #7d64ff;
169+
}
184170
}
185171

186172
.type {
@@ -202,7 +188,7 @@
202188
}
203189

204190
.description {
205-
margin-bottom: 15px;
191+
margin-bottom: 21px;
206192
font-size: $font-size-sm;
207193
line-height: $line-height-sm;
208194
margin-top: 10px;
@@ -212,23 +198,32 @@
212198
.external {
213199
margin-top: auto;
214200
display: flex;
215-
gap: 16px;
201+
align-items: center;
202+
column-gap: 10px;
203+
width: 100%;
216204
font-weight: 400;
217205
font-size: 13px;
218206
line-height: 20px;
219-
color: #9691af;
207+
color: #8b85ad;
208+
letter-spacing: -0.05em;
209+
pointer-events: none;
210+
211+
@media (min-width: 1200px) and (max-width: 1320px) {
212+
column-gap: 5px;
213+
}
220214
}
221215

222216
.stars,
223217
.cloud {
224218
display: flex;
225219
align-items: center;
220+
white-space: nowrap;
226221

227222
&:before {
228223
content: '';
229224
display: inline-block;
230225
vertical-align: middle;
231-
margin-right: 8px;
226+
margin-right: 4px;
232227
background-position: center;
233228
background-repeat: no-repeat;
234229
background-size: contain;
@@ -239,7 +234,6 @@
239234
&:before {
240235
width: 14px;
241236
height: 14px;
242-
margin: 0 4px;
243237
background-image: url(./svg/star.inline.svg);
244238
}
245239
}

src/components/shared/extension-card/extension-card.view.js

Lines changed: 54 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import classNames from 'classnames';
2+
import { CheckboxField } from 'components/shared/checkbox-field';
23
import {
34
ItemCard,
45
styles as itemCardStyles,
@@ -7,15 +8,32 @@ import React from 'react';
78

89
import styles from './extension-card.module.scss';
910

11+
const parseString = (str) => {
12+
let string = str.replace(/-/gi, '<wbr />-');
13+
14+
// Find the last occurrence of '<wbr />'
15+
const lastIndex = string.lastIndexOf('<wbr />');
16+
17+
if (lastIndex !== -1) {
18+
// Wrap the part of the string after the last '<wbr />' with 'span' tags
19+
const prefix = string.slice(0, lastIndex);
20+
const suffix = string.slice(lastIndex + 8); // Length of '<wbr />'
21+
22+
// eslint-disable-next-line max-len
23+
string = `${prefix}<wbr />-<span class="no-wrap">${suffix}<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 14 14" fill="none" style="margin-left: 8px"><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.4" d="M4.429 1H2.714C1 1 1 1 1 2.714v9.352C1 13 1 13 2.714 13h8.572C13 13 13 13 13 11.286V9.57M7.857 1H13m0 0v5.143M13 1 6.143 7.857"/></svg></span>`;
24+
}
25+
26+
return string;
27+
};
28+
1029
export const ExtensionCard = ({
1130
extension,
1231
searchTerm = '',
1332
hasCheckbox = false,
1433
isChecked = false,
1534
onCheckboxClick = () => {},
1635
}) => {
17-
const { name, description, tiers, stars, cloudEnabled, url, logo } =
18-
extension;
36+
const { name, description, tiers, stars, cloudEnabled, url } = extension;
1937
const extensionName = searchTerm
2038
? name.replace(
2139
new RegExp(searchTerm, 'gi'),
@@ -48,9 +66,9 @@ export const ExtensionCard = ({
4866
</ItemCard>
4967
);
5068
}
69+
5170
return (
52-
// eslint-disable-next-line react/jsx-indent
53-
<ItemCard as="a" href={url}>
71+
<ItemCard as="div">
5472
<div className={className}>{children}</div>
5573
</ItemCard>
5674
);
@@ -63,44 +81,47 @@ export const ExtensionCard = ({
6381
}`}
6482
>
6583
<div className={styles.content}>
66-
<ul className={styles.tiersWrapper}>
67-
{tiers.map((tier, index) => (
68-
<li
69-
className={classNames(
70-
styles.tier,
71-
tier === 'Official' && styles.tierOfficial,
72-
tier === 'Verified' && styles.tierVerified,
73-
tier === 'Community' && styles.tierCommunity,
74-
)}
75-
key={index}
76-
>
77-
<span>{tier}</span>
78-
</li>
79-
))}
80-
{logo && (
81-
<li className={styles.logoWrapper}>
82-
<img
83-
className={styles.logo}
84-
src={logo}
85-
width="auto"
86-
height="24"
87-
alt={name}
88-
loading="lazy"
89-
/>
90-
</li>
91-
)}
92-
</ul>
84+
{hasCheckbox && (
85+
<div className={styles.checkbox}>
86+
<CheckboxField
87+
id={name}
88+
checked={isChecked}
89+
onChange={onCheckboxClick}
90+
accessible={false}
91+
/>
92+
</div>
93+
)}
9394
<div className={styles.nameWrapper}>
94-
<span
95+
<a
9596
className={styles.name}
96-
dangerouslySetInnerHTML={{ __html: extensionName }}
97+
href={url}
98+
target="_blank"
99+
rel="noreferrer"
100+
dangerouslySetInnerHTML={{
101+
__html: parseString(extensionName),
102+
}}
97103
/>
98104
</div>
99105
<span
100106
className={styles.description}
101107
dangerouslySetInnerHTML={{ __html: extensionDescription }}
102108
/>
103109
<div className={styles.external}>
110+
<ul className={styles.tiersWrapper}>
111+
{tiers.map((tier, index) => (
112+
<li
113+
className={classNames(
114+
styles.tier,
115+
tier === 'Official' && styles.tierOfficial,
116+
tier === 'Verified' && styles.tierVerified,
117+
tier === 'Community' && styles.tierCommunity,
118+
)}
119+
key={index}
120+
>
121+
<span>{tier}</span>
122+
</li>
123+
))}
124+
</ul>
104125
{stars && <span className={styles.stars}>{stars}</span>}
105126
{cloudEnabled && (
106127
<span className={styles.cloud}>Available in cloud</span>

src/styles/parts/global.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ video {
8282
}
8383
}
8484

85+
.no-wrap {
86+
white-space: nowrap;
87+
}
88+
8589
body .show-md-down {
8690
@include md-down {
8791
display: initial;

src/svg/external-link.inline.svg

Lines changed: 1 addition & 0 deletions
Loading

0 commit comments

Comments
 (0)