Skip to content

Commit 1e920dd

Browse files
adding the vn-dial widget 🔥 (#35)
* adding the vn-dial component 🔥 * using the vn-slider model for vn-dial too 🔥 * adding the demo for the vn-dial component 🌸
1 parent 74af2e9 commit 1e920dd

File tree

7 files changed

+112
-6
lines changed

7 files changed

+112
-6
lines changed

demo/Header.vue

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
<vn-text>Here's a progres bar</vn-text>
2323
<vn-progress-bar :value="45" />
2424
<vn-combobox :items="data" />
25+
<vn-dial :notchesVisible="true" v-model="dialValue" />
26+
<vn-text>{{dialValue}}</vn-text>
2527
</vn-view>
2628
</template>
2729

@@ -32,6 +34,7 @@ export default {
3234
setup() {
3335
const count = ref(0);
3436
const viewVisible = ref(true);
37+
const dialValue = ref(0);
3538
const data = [
3639
{text: "item 1"},
3740
{text: "item 2"},
@@ -60,11 +63,8 @@ export default {
6063
line1Text,
6164
link,
6265
data,
66+
dialValue,
6367
};
6468
}
6569
}
66-
</script>
67-
68-
<style>
69-
70-
</style>
70+
</script>

src/vueLoader.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export const compilerOptions: CompilerOptions = {
3232
directiveToUse = V_MODEL_TEXT;
3333
break;
3434
case 'vn-slider':
35+
case 'vn-dial':
3536
directiveToUse = V_MODEL_SLIDER;
3637
break;
3738
case 'vn-spinbox':

src/widgets/Dial/VNDial.ts

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
import { NodeWidget, QDial } from '@nodegui/nodegui';
2+
import { Prop, PropSetters } from 'renderer/patchProp';
3+
import { VNWidget } from 'widgets/config';
4+
import { ViewProps, viewPropsSetters } from '../View/VNView';
5+
6+
/**
7+
* The Dial provides ability to add and manipulate native dial slider widgets. It is based on
8+
* [NodeGui's QDial](https://docs.nodegui.org/docs/api/generated/classes/qdial/).
9+
*
10+
* ## Usage
11+
*
12+
* ```html
13+
* <template>
14+
* <vn-view :style="'flex-direction: \'column\''">
15+
* <vn-dial :notchesVisible="true" v-model="dialValue" />
16+
* <vn-text>{{dialValue}}</vn-text>
17+
* </vn-view>
18+
* </template>
19+
*
20+
* <script>
21+
* import { ref } from 'vue';
22+
*
23+
* export default {
24+
* setup() {
25+
* const dialValue = ref(0);
26+
* return {
27+
* dialValue
28+
* };
29+
* }
30+
* }
31+
* </script>
32+
* ```
33+
*
34+
* ## What it looks like?
35+
*
36+
* ![dial-demo](/img/vn-dial.gif)
37+
*
38+
* ## Props and styling
39+
*
40+
* You can find all the props `vn-dial` accepts listed below.
41+
* Apart from this, you can take a look at the [styling](/docs/guides/3-styling)
42+
* and [event handling](/docs/guides/5-handle-events) docs
43+
*/
44+
export interface DialProps extends ViewProps {
45+
notchesVisible?: boolean;
46+
wrapping?: boolean;
47+
notchTarget?: number;
48+
}
49+
50+
const dialPropsSetters: PropSetters<VNDial, DialProps> = {
51+
...viewPropsSetters,
52+
notchesVisible: (widget: VNDial, _, nextValue: boolean) => {
53+
widget.setNotchesVisible(nextValue);
54+
},
55+
wrapping: (widget: VNDial, _, nextValue: boolean) => {
56+
widget.setWrapping(nextValue);
57+
},
58+
notchTarget: (widget: VNDial, _, nextValue: number) => {
59+
widget.setNotchTarget(nextValue);
60+
},
61+
};
62+
63+
/** @internal */
64+
export class VNDial extends QDial implements VNWidget<DialProps> {
65+
patchProp(
66+
key: keyof DialProps,
67+
prevValue: Prop<DialProps, typeof key>,
68+
nextValue: Prop<DialProps, typeof key>,
69+
) {
70+
const propSetter = dialPropsSetters[key];
71+
if (propSetter !== undefined) { propSetter(this, prevValue as never, nextValue as never); }
72+
}
73+
74+
insertChild() {
75+
throw new Error('Cannot add child to Dial elements');
76+
}
77+
78+
getNextSibling(): NodeWidget<any> | null {
79+
throw new Error('Dial elements cannot have children');
80+
}
81+
82+
insertBefore() {
83+
throw new Error('Cannot add child to Dial elements');
84+
}
85+
86+
removeChild() {
87+
throw new Error('Cannot remove/add child to Dial elements');
88+
}
89+
}

src/widgets/Dial/index.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { WidgetConfig } from '../config';
2+
import { VNDial, DialProps } from './VNDial';
3+
4+
class DialConfig implements WidgetConfig<DialProps> {
5+
parentNode: any;
6+
7+
createElement() {
8+
return new VNDial();
9+
}
10+
}
11+
12+
export default DialConfig;

src/widgets/nativeWidget.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ export type ValidNativeWidgets = 'vn-image' |
99
'vn-slider' |
1010
'vn-spinbox' |
1111
'vn-progress-bar' |
12-
'vn-combobox';
12+
'vn-combobox' |
13+
'vn-dial';
1314

1415
// Add vue-nodegui widgets here
1516
// whenever new ones are created
@@ -26,6 +27,7 @@ const nativeWidgets: {[key in ValidNativeWidgets]: boolean} = {
2627
'vn-spinbox': true,
2728
'vn-progress-bar': true,
2829
'vn-combobox': true,
30+
'vn-dial': true,
2931
};
3032

3133
export const isNativeWidget = (type: ValidNativeWidgets) => !!nativeWidgets[type];

src/widgets/widgetMap.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import SliderConfig from './Slider';
1010
import SpinBoxConfig from './SpinBox';
1111
import ProgressBarConfig from './ProgressBar';
1212
import ComboBoxConfig from './ComboBox';
13+
import DialConfig from './Dial';
1314
import { ValidNativeWidgets } from './nativeWidget';
1415
import { WidgetConfig } from './config';
1516

@@ -30,6 +31,7 @@ const widgetMap: WidgetMap = {
3031
'vn-spinbox': new SpinBoxConfig(),
3132
'vn-progress-bar': new ProgressBarConfig(),
3233
'vn-combobox': new ComboBoxConfig(),
34+
'vn-dial': new DialConfig(),
3335
};
3436

3537
const getConfigByType = (type: ValidNativeWidgets) => {

website/static/img/vn-dial.gif

209 KB
Loading

0 commit comments

Comments
 (0)