Skip to content

Commit

Permalink
feat(select): border dash
Browse files Browse the repository at this point in the history
  • Loading branch information
CyanSalt committed Jul 23, 2023
1 parent 291806d commit 874e3a6
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 3 deletions.
2 changes: 1 addition & 1 deletion docs/components/progress.md
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ import { RProgress, RSpace } from 'roughness'
</template>
<template #body:border-dash:default>

`8px` when hovered, `none` else
`none`

</template>
<template #body:border-dash:description>
Expand Down
36 changes: 35 additions & 1 deletion docs/components/select.md
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ See [Checkbox Tree](/components/checkbox#tree).
<RSpace overflow>
<RTable
:columns="['name', 'values', 'default', 'description']"
:rows="['border-color', 'border-width', 'dropdown-border-width', 'dropdown-padding-block', 'dropdown-padding-inline']"
:rows="['border-color', 'border-width', 'border-dash', 'dropdown-border-width', 'dropdown-border-dash', 'dropdown-padding-block', 'dropdown-padding-inline']"
>
<template #body:*:name="{ row }">--r-select-{{ row }}</template>
Expand Down Expand Up @@ -283,6 +283,26 @@ See [Checkbox Tree](/components/checkbox#tree).
Width of the select control border.
</template>

<template #body:border-dash:values>

`<length> +` or `none`

</template>
<template #body:border-dash:default>

`none`

</template>
<template #body:border-dash:description>

List of comma and/or whitespace separated the lengths of alternating dashes and gaps of the select border.

An odd number of values will be repeated to yield an even number of values. Thus, `8` is equivalent to `8 8`.

See [`stroke-dasharray`](https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/stroke-dasharray).

</template>

<template #body:dropdown-border-width:values>

`<length>`
Expand All @@ -297,6 +317,20 @@ See [Checkbox Tree](/components/checkbox#tree).
Width of the select dropdown border.
</template>

<template #body:dropdown-border-dash:values>

`<length> +` or `none`

</template>
<template #body:dropdown-border-dash:default>

`none`

</template>
<template #body:dropdown-border-dash:description>
List of comma and/or whitespace separated the lengths of alternating dashes and gaps of the select dropdown border.
</template>

<template #body:dropdown-padding-block:values>

1-2 `<length>` or `<percentage>`
Expand Down
10 changes: 9 additions & 1 deletion src/select/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { sentenceCase, useReactionState } from '../common/utils'
import { nameInjection } from '../form/utils'
import RGraphics from '../graphics/index.vue'
import type { GraphicsProps } from '../graphics/utils'
import { getSVGSize, measureSVGSize } from '../graphics/utils'
import { getSVGSize, measureSVGSize, measureSVGSizeAsArray } from '../graphics/utils'
import RIcon from '../icon/index.vue'
defineOptions({
Expand Down Expand Up @@ -115,6 +115,8 @@ function draw(rc: RoughSVG, svg: SVGSVGElement) {
getReactionState()
const { width, height } = getSVGSize(svg)
const strokeWidth = measureSVGSize(svg, '--r-select-border-width') ?? 0
const strokeLineDash = measureSVGSizeAsArray(svg, '--r-select-border-dash')
?.map(value => value ?? 0) ?? undefined
const padding = 2
const rect = rc.rectangle(
padding,
Expand All @@ -124,6 +126,7 @@ function draw(rc: RoughSVG, svg: SVGSVGElement) {
{
stroke: 'var(--r-select-border-color)',
strokeWidth,
strokeLineDash,
},
)
svg.appendChild(rect)
Expand All @@ -132,10 +135,13 @@ function draw(rc: RoughSVG, svg: SVGSVGElement) {
function drawDropdown(rc: RoughSVG, svg: SVGSVGElement) {
const { width, height } = getSVGSize(svg)
const strokeWidth = measureSVGSize(svg, '--r-select-dropdown-border-width') ?? 0
const strokeLineDash = measureSVGSizeAsArray(svg, '--r-select-dropdown-border-dash')
?.map(value => value ?? 0) ?? undefined
const padding = 2
const rectangle = rc.rectangle(padding, padding, width - padding * 2, height - padding * 2, {
stroke: 'var(--r-select-border-color)',
strokeWidth,
strokeLineDash,
fill: 'var(--r-common-background-color)',
fillStyle: 'solid',
})
Expand Down Expand Up @@ -203,7 +209,9 @@ provide(labelsInjection, labels)
.r-select {
--r-select-border-color: var(--r-common-text-color);
--r-select-border-width: 1px;
--r-select-border-dash: none;
--r-select-dropdown-border-width: 1px;
--r-select-dropdown-border-dash: none;
--r-select-dropdown-padding-block: 12px;
--r-select-dropdown-padding-inline: 12px;
position: relative;
Expand Down

0 comments on commit 874e3a6

Please sign in to comment.