Skip to content

Commit 46653c2

Browse files
committed
(connections): Add method to convert color
1 parent c0afa42 commit 46653c2

File tree

3 files changed

+18
-15
lines changed

3 files changed

+18
-15
lines changed

src/connections/dist/connections.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/connections/src/index.js

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,6 @@
11
registerPaint(
22
'connections',
33
class {
4-
constructor() {
5-
this.CONNECTIONS_PROPS = [
6-
'--connections-particleColor',
7-
'--connections-lineColor',
8-
'--connections-particleAmount',
9-
'--connections-defaultRadius',
10-
'--connections-variantRadius',
11-
'--connections-linkRadius'
12-
]
13-
}
14-
154
static get inputProperties() {
165
return [
176
'--connections-particleColor',
@@ -23,6 +12,17 @@ registerPaint(
2312
]
2413
}
2514

15+
hexToRgb(hex) {
16+
let colors = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex)
17+
return colors
18+
? [
19+
parseInt(colors[1], 16),
20+
parseInt(colors[2], 16),
21+
parseInt(colors[3], 16)
22+
]
23+
: null
24+
}
25+
2626
parseProps(props) {
2727
return [
2828
'--connections-particleColor',
@@ -56,7 +56,10 @@ registerPaint(
5656
] = this.parseProps(props)
5757

5858
let particles = []
59-
const [r, g, b] = lineColor.match(/\d+/g)
59+
const isHexColor = /^#([0-9A-F]{3}){1,2}$/i.test(lineColor)
60+
const [r, g, b] = isHexColor
61+
? this.hexToRgb(lineColor)
62+
: lineColor.match(/\d+/g)
6063

6164
const particle = (x, y) => {
6265
let radius = +defaultRadius + Math.random() * +variantRadius

src/connections/test/styles.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ body {
3636
}
3737

3838
.connections {
39-
--connections-particleColor: rgb(150,180,200);
40-
--connections-lineColor: rgb(150,180,200);
39+
--connections-particleColor: #96b4c8;
40+
--connections-lineColor: #96b4c8;
4141
--connections-particleAmount: 200;
4242
--connections-defaultRadius: 2;
4343
--connections-variantRadius: 1;

0 commit comments

Comments
 (0)