Skip to content

Commit

Permalink
refactor: style layer border custom property
Browse files Browse the repository at this point in the history
  • Loading branch information
guiseek committed Aug 23, 2024
1 parent ef35e26 commit 98a3c65
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/features/canvas/canvas.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {builtIn} from '@websqnl/elements/shared'
import {Layer} from '@features/layers'
import {Vector2} from '@shared/utils'
import {getCustomProperty, Vector2} from '@shared/utils'

@builtIn('canvas', 'cf-canvas')
class Canvas extends HTMLCanvasElement {
Expand Down Expand Up @@ -157,7 +157,10 @@ class Canvas extends HTMLCanvasElement {
path.rect(x, y, width, height)

this.context!.lineWidth = 2
this.context!.strokeStyle = 'rgba(255, 13, 233, 0.4)'

const style = `rgba(${getCustomProperty('--cf-primary-rgb')}, 0.4)`
this.context!.strokeStyle = style

this.context!.stroke(path)
}
}
Expand Down
1 change: 1 addition & 0 deletions src/shared/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export * from './iterators';
export * from './loaders';
export * from './math';
export * from './styles';
export * from './async';
export * from './form-value';
export * from './serialize';
Expand Down
6 changes: 6 additions & 0 deletions src/shared/utils/styles/get-custom-property.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
type CustomProperty = `--cf-primary-rgb` | `--cf-onprimary-rgb` | `--cf-surface-rgb` | `--cf-onsurface-rgb`

export const getCustomProperty = (property: CustomProperty) => {
return getComputedStyle(document.documentElement).getPropertyValue(property)

}
1 change: 1 addition & 0 deletions src/shared/utils/styles/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './get-custom-property';

0 comments on commit 98a3c65

Please sign in to comment.