Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[beam] Segmented Display Component #228

Merged
merged 1 commit into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions beam/src/components/SegmentedDisplay.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<template>
<div class="segmented-display" :style="{ background: getColor(displayColor) }">
<h1 class="segmented-display-output" :style="{ color: getColor(textColor) }">{{ getOutput }}</h1>
</div>
</template>
<script setup lang="ts">
import { ref, defineProps, computed } from 'vue'

const {
displayInput = 120.2568,
decimalPlaces = 2,
displayColor = 'gray',
textColor = 'white',
} = defineProps<{
displayInput?: number
decimalPlaces?: number
displayColor?: Color
textColor?: Color
}>()

const getOutput = computed(() => {
if (displayInput.length == 0) return Number(0).toFixed(decimalPlaces)
return displayInput.toFixed(decimalPlaces)
})

const getColor = color => {
return color.substr(0, 2) == '--' ? `var(${color})` : color
}
</script>

<style scoped>
.segmented-display {
width: 100%;
padding: 1rem;
box-sizing: border-box;
display: flex;
background: var(--sc-segmented-display-background);
align-items: center;
justify-content: flex-end;
}
.segmented-display-output {
text-align: right;
font-family: Segment7, Arimo, sans-serif;
font-weight: normal;
font-size: var(--sc-segemented-display-font-size);
padding: 0;
margin: 0;
letter-spacing: 0.3rem;
margin-bottom: -0.7rem;
color: var(--sc-segmented-display-color);
}
</style>
3 changes: 3 additions & 0 deletions beam/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import ListItem from './components/ListItem.vue'
import ListView from './components/ListView.vue'
import Navbar from './components/Navbar.vue'
import ScanInput from './components/ScanInput.vue'
import SegmentedDisplay from './components/SegmentedDisplay.vue'
import SplitColumn from './components/SplitColumn.vue'
import ToggleArrow from './components/ToggleArrow.vue'
import { useMqttStream } from './composables/mqtt'
Expand Down Expand Up @@ -52,6 +53,7 @@ function install(app: App /* options */) {
app.component('ListView', ListView)
app.component('Navbar', Navbar)
app.component('ScanInput', ScanInput)
app.component('SegmentedDisplay', SegmentedDisplay)
app.component('SplitColumn', SplitColumn)
app.component('ToggleArrow', ToggleArrow)
}
Expand All @@ -77,6 +79,7 @@ export {
ListView,
Navbar,
ScanInput,
SegmentedDisplay,
SplitColumn,
ToggleArrow,
install,
Expand Down
7 changes: 7 additions & 0 deletions beam/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ export type ListViewItem = {
route?: string
}

type RGB = `rgb(${number}, ${number}, ${number})`
type HSL = `hsl(${number}, ${number}%, ${number}%)`
type HSLA = `hsl(${number}, ${number}%, ${number}%), ${number}`
type RGBA = `rgba(${number}, ${number}, ${number}, ${number})`
type HEX = `#${string}`

export type Color = RGB | RGBA | HEX | HSL | HSLA | string
/**
* MQTT stream options
* @public
Expand Down
Binary file added beam/themes/Segment7Standard.otf
Binary file not shown.
4 changes: 4 additions & 0 deletions beam/themes/Segment7Standard.otf:Zone.Identifier
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[ZoneTransfer]
ZoneId=3
ReferrerUrl=https://fontlibrary.org/en/font/segment7
HostUrl=https://fontlibrary.org/assets/downloads/segment7/4cc82137fc130708919bf201c0dc9aae/segment7.zip
8 changes: 8 additions & 0 deletions beam/themes/beam.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
@import url('https://fonts.googleapis.com/css2?family=Arimo:ital,wght@0,400;0,500;0,600;0,700;1,400;1,500;1,600;1,700&display=swap');

@font-face {
font-family: 'Segment7';
src: url('./Segment7Standard.otf');
}
/* Global Beam Styles */

:root {
Expand All @@ -22,6 +26,10 @@
--sc-list-margin: 0.625rem;

--sc-cell-changed-color: #d8edff;

--sc-segemented-display-font-size: 4.5rem;
--sc-segmented-display-background: #404040;
--sc-segmented-display-color: #b0b0b0;
}

/* body {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@stonecrop/beam",
"comment": "added SegementedDisplay component",
"type": "none"
}
],
"packageName": "@stonecrop/beam"
}
3 changes: 3 additions & 0 deletions common/reviews/api/beam.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import ListView from './components/ListView.vue';
import Navbar from './components/Navbar.vue';
import { Ref } from 'vue';
import ScanInput from './components/ScanInput.vue';
import SegmentedDisplay from './components/SegmentedDisplay.vue';
import SplitColumn from './components/SplitColumn.vue';
import ToggleArrow from './components/ToggleArrow.vue';

Expand Down Expand Up @@ -96,6 +97,8 @@ export { Navbar }

export { ScanInput }

export { SegmentedDisplay }

export { SplitColumn }

export { ToggleArrow }
Expand Down
19 changes: 19 additions & 0 deletions examples/beam/components.story.vue
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,19 @@
<Variant title="progress block">
<BeamProgress :complete="workOrder.complete" />
</Variant>
<Variant title="Segmented Display">
<template #controls>
<HstText v-model="displayOptions.displayColor" title="Display Background Color" />
<HstText v-model="displayOptions.textColor" title="Display Text Color" />
<HstNumber v-model="displayOptions.displayInput" title="Display Number Input" />
<HstNumber v-model="displayOptions.decimalPlaces" :step="1" title="Decimal Places" />
</template>
<SegmentedDisplay
:display-color="displayOptions.displayColor"
:text-color="displayOptions.textColor"
:display-input="displayOptions.displayInput"
:decimal-places="displayOptions.decimalPlaces"></SegmentedDisplay>
</Variant>
</Story>
</template>

Expand All @@ -77,4 +90,10 @@ import { reactive } from 'vue'
const workOrder = reactive({
complete: false,
})
const displayOptions = reactive({
displayColor: '--sc-segmented-display-background',
textColor: '--sc-segmented-display-color',
displayInput: 0,
decimalPlaces: 2,
})
</script>
Loading