Skip to content

Commit cf00a10

Browse files
author
namudara
committed
HT-964: Introduce a slot to add any html content for radio field label
1 parent b1bd9a4 commit cf00a10

2 files changed

Lines changed: 82 additions & 14 deletions

File tree

components/src/core/components/Input/RadioInput.vue

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,30 @@
33
<label :class="labelClasses">
44
<template v-if="labelPosition === 'left'">
55
<div class="oxd-radio-option-label">
6-
{{ optionLabel }}
6+
<slot v-if="!optionLabel" name="label"></slot>
7+
<template v-else>
8+
{{ optionLabel }}
9+
</template>
710
</div>
811
</template>
9-
<input
10-
type="radio"
11-
@focus="onFocus"
12-
@blur="onBlur"
13-
@change="onChange"
14-
v-bind="$attrs"
15-
v-model="checked"
16-
:disabled="disabled"
17-
/>
12+
<input type="radio" @focus="onFocus" @blur="onBlur" @change="onChange" v-bind="$attrs" v-model="checked"
13+
:disabled="disabled" />
1814
<span :class="classes" :style="style" class="oxd-radio-input"></span>
1915
<template v-if="labelPosition === 'right'">
2016
<div class="oxd-radio-option-label">
21-
{{ optionLabel }}
17+
<slot v-if="!optionLabel" name="label"></slot>
18+
<template v-else>
19+
{{ optionLabel }}
20+
</template>
2221
</div>
2322
</template>
2423
</label>
2524
</div>
2625
</template>
2726

2827
<script lang="ts">
29-
import {defineComponent} from 'vue';
30-
import {Position, LABEL_POSITIONS, RIGHT} from './types';
28+
import { defineComponent } from 'vue';
29+
import { Position, LABEL_POSITIONS, RIGHT } from './types';
3130
3231
export interface State {
3332
focused: boolean;
@@ -50,7 +49,7 @@ export default defineComponent({
5049
labelPosition: {
5150
type: String,
5251
default: RIGHT,
53-
validator: function(value: Position) {
52+
validator: function (value: Position) {
5453
return LABEL_POSITIONS.indexOf(value) !== -1;
5554
},
5655
},

storybook/stories/core/components/Input/RadioInput.stories.js

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import RadioInput from '@orangehrm/oxd/core/components/Input/RadioInput';
2+
import Icon from '@orangehrm/oxd/core/components/Icon/Icon';
23
import {
34
RIGHT,
45
LABEL_POSITIONS,
@@ -69,6 +70,15 @@ export default {
6970
type: {summary: 'Emit when update the value'},
7071
},
7172
},
73+
label: {
74+
control: {type: 'text'},
75+
table: {
76+
type: {
77+
summary:
78+
'Named slot for custom label content. Only used if optionLabel prop is not provided. Allows full customization (text, icons, secondary labels, etc.)',
79+
},
80+
},
81+
},
7282
},
7383
};
7484

@@ -226,3 +236,62 @@ VmodelMultiple.parameters = {
226236
},
227237
},
228238
};
239+
240+
const CustomLabelSlotSample = () => ({
241+
data() {
242+
return {
243+
selected: '',
244+
};
245+
},
246+
components: {
247+
'oxd-radio-input': RadioInput,
248+
'oxd-icon': Icon,
249+
},
250+
template: `<div>
251+
<oxd-radio-input v-model="selected" id="radio1" value="fulltime">
252+
<template #label>
253+
<strong>Full Time</strong>
254+
<span style="opacity: 0.5; margin-left: 0.25rem;">(40 hours/week)</span>
255+
<oxd-icon name="clock" style="margin-left: 0.5rem;" />
256+
</template>
257+
</oxd-radio-input>
258+
<br/>
259+
<oxd-radio-input v-model="selected" id="radio2" value="parttime">
260+
<template #label>
261+
<strong>Part Time</strong>
262+
<span style="opacity: 0.5; margin-left: 0.25rem;">(20 hours/week)</span>
263+
<oxd-icon name="time" style="margin-left: 0.5rem;" />
264+
</template>
265+
</oxd-radio-input>
266+
<br/>
267+
<span>Selected: {{selected}}</span>
268+
</div>`,
269+
});
270+
271+
export const CustomLabelSlot = CustomLabelSlotSample.bind({});
272+
273+
CustomLabelSlot.parameters = {
274+
docs: {
275+
source: {
276+
code: `<div>
277+
<oxd-radio-input v-model="selected" id="radio1" value="fulltime">
278+
<template #label>
279+
<strong>Full Time</strong>
280+
<span style="opacity: 0.5; margin-left: 0.25rem;">(40 hours/week)</span>
281+
<oxd-icon name="clock" style="margin-left: 0.5rem;" />
282+
</template>
283+
</oxd-radio-input>
284+
<br/>
285+
<oxd-radio-input v-model="selected" id="radio2" value="parttime">
286+
<template #label>
287+
<strong>Part Time</strong>
288+
<span style="opacity: 0.5; margin-left: 0.25rem;">(20 hours/week)</span>
289+
<oxd-icon name="time" style="margin-left: 0.5rem;" />
290+
</template>
291+
</oxd-radio-input>
292+
<br/>
293+
<span>Selected: {{selected}}</span>
294+
</div>`,
295+
},
296+
},
297+
};

0 commit comments

Comments
 (0)