New Component: `RadioButtonGroup`

pull/6632/head
Mert Sincan 2024-10-20 23:29:29 +01:00
parent de8ee98cb5
commit 2458008489
9 changed files with 247 additions and 4 deletions

View File

@ -6,7 +6,7 @@
:class="[cx('input'), inputClass]" :class="[cx('input'), inputClass]"
:style="inputStyle" :style="inputStyle"
:value="value" :value="value"
:name="name" :name="groupName"
:checked="checked" :checked="checked"
:tabindex="tabindex" :tabindex="tabindex"
:disabled="disabled" :disabled="disabled"
@ -34,6 +34,11 @@ export default {
extends: BaseRadioButton, extends: BaseRadioButton,
inheritAttrs: false, inheritAttrs: false,
emits: ['change', 'focus', 'blur'], emits: ['change', 'focus', 'blur'],
inject: {
$pcRadioButtonGroup: {
default: undefined
}
},
methods: { methods: {
getPTOptions(key) { getPTOptions(key) {
const _ptm = key === 'root' ? this.ptmi : this.ptm; const _ptm = key === 'root' ? this.ptmi : this.ptm;
@ -49,7 +54,7 @@ export default {
if (!this.disabled && !this.readonly) { if (!this.disabled && !this.readonly) {
const newModelValue = this.binary ? !this.checked : this.value; const newModelValue = this.binary ? !this.checked : this.value;
this.updateValue(newModelValue, event); this.$pcRadioButtonGroup ? this.$pcRadioButtonGroup.updateValue(newModelValue, event) : this.updateValue(newModelValue, event);
this.$emit('change', event); this.$emit('change', event);
} }
}, },
@ -62,8 +67,13 @@ export default {
} }
}, },
computed: { computed: {
groupName() {
return this.$pcRadioButtonGroup ? this.$pcRadioButtonGroup.groupName : this.name;
},
checked() { checked() {
return this.d_value != null && (this.binary ? !!this.d_value : equals(this.d_value, this.value)); const value = this.$pcRadioButtonGroup ? this.$pcRadioButtonGroup.d_value : this.d_value;
return value != null && (this.binary ? !!value : equals(value, this.value));
} }
} }
}; };

View File

@ -125,7 +125,7 @@ const classes = {
{ {
'p-radiobutton-checked': instance.checked, 'p-radiobutton-checked': instance.checked,
'p-disabled': props.disabled, 'p-disabled': props.disabled,
'p-invalid': instance.$invalid, 'p-invalid': instance.$pcRadioButtonGroup ? instance.$pcRadioButtonGroup.$invalid : instance.$invalid,
'p-variant-filled': instance.$variant === 'filled' 'p-variant-filled': instance.$variant === 'filled'
} }
], ],

View File

@ -0,0 +1,16 @@
<script>
import BaseEditableHolder from '@primevue/core/baseeditableholder';
import RadioButtonGroupStyle from 'primevue/radiobuttongroup/style';
export default {
name: 'BaseRadioButtonGroup',
extends: BaseEditableHolder,
style: RadioButtonGroupStyle,
provide() {
return {
$pcRadioButtonGroup: this,
$parentInstance: this
};
}
};
</script>

View File

@ -0,0 +1,135 @@
/**
*
* FloatLabel visually integrates a label with its form element.
*
* [Live Demo](https://www.primevue.org/floatlabel/)
*
* @module floatlabel
*
*/
import type { DefineComponent, DesignToken, EmitFn, PassThrough } from '@primevue/core';
import type { ComponentHooks } from '@primevue/core/basecomponent';
import type { PassThroughOptions } from 'primevue/passthrough';
import { TransitionProps, VNode } from 'vue';
export declare type FloatLabelPassThroughOptionType = FloatLabelPassThroughAttributes | ((options: FloatLabelPassThroughMethodOptions) => FloatLabelPassThroughAttributes | string) | string | null | undefined;
export declare type FloatLabelPassThroughTransitionType = TransitionProps | ((options: FloatLabelPassThroughMethodOptions) => TransitionProps) | undefined;
/**
* Custom passthrough(pt) option method.
*/
export interface FloatLabelPassThroughMethodOptions {
/**
* Defines instance.
*/
instance: any;
/**
* Defines valid properties.
*/
props: FloatLabelProps;
/**
* Defines valid attributes.
*/
attrs: any;
/**
* Defines parent options.
*/
parent: any;
/**
* Defines passthrough(pt) options in global config.
*/
global: object | undefined;
}
/**
* Custom passthrough(pt) options.
* @see {@link FloatLabelProps.pt}
*/
export interface FloatLabelPassThroughOptions {
/**
* Used to pass attributes to the root's DOM element.
*/
root?: FloatLabelPassThroughOptionType;
/**
* Used to manage all lifecycle hooks.
* @see {@link BaseComponent.ComponentHooks}
*/
hooks?: ComponentHooks;
}
/**
* Custom passthrough attributes for each DOM elements
*/
export interface FloatLabelPassThroughAttributes {
[key: string]: any;
}
/**
* Defines valid properties in FloatLabel component.
*/
export interface FloatLabelProps {
/**
* It generates scoped CSS variables using design tokens for the component.
*/
dt?: DesignToken<any>;
/**
* Used to pass attributes to DOM elements inside the component.
* @type {FloatLabelPassThroughOptions}
*/
pt?: PassThrough<FloatLabelPassThroughOptions>;
/**
* Used to configure passthrough(pt) options of the component.
* @type {PassThroughOptions}
*/
ptOptions?: PassThroughOptions;
/**
* When enabled, it removes component related styles in the core.
* @defaultValue false
*/
unstyled?: boolean;
/**
* Defines the positioning of the label relative to the input.
* @defaultValue false
*/
variant?: 'over' | 'in' | 'on' | undefined;
}
/**
* Defines valid slots in FloatLabel component.
*/
export interface FloatLabelSlots {
/**
* Default content slot.
*/
default: () => VNode[];
}
/**
* Defines valid emits in FloatLabel component.
*/
export interface FloatLabelEmitsOptions {}
export declare type FloatLabelEmits = EmitFn<FloatLabelEmitsOptions>;
/**
* **PrimeVue - FloatLabel**
*
* _FloatLabel visually integrates a label with its form element._
*
* [Live Demo](https://www.primevue.org/inputtext/)
* --- ---
* ![PrimeVue](https://primefaces.org/cdn/primevue/images/logo-100.png)
*
* @group Component
*
*/
declare const FloatLabel: DefineComponent<FloatLabelProps, FloatLabelSlots, FloatLabelEmits>;
declare module 'vue' {
export interface GlobalComponents {
FloatLabel: DefineComponent<FloatLabelProps, FloatLabelSlots, FloatLabelEmits>;
}
}
export default FloatLabel;

View File

@ -0,0 +1,29 @@
<template>
<div :class="cx('root')" v-bind="ptmi('root')">
<slot />
</div>
</template>
<script>
import { uuid } from '@primeuix/utils';
import BaseRadioButtonGroup from './BaseRadioButtonGroup.vue';
export default {
name: 'RadioButtonGroup',
extends: BaseRadioButtonGroup,
inheritAttrs: false,
data() {
return {
groupName: this.name
};
},
watch: {
name(newValue) {
this.groupName = newValue || uuid('radiobutton-group-');
}
},
mounted() {
this.groupName = this.groupName || uuid('radiobutton-group-');
}
};
</script>

View File

@ -0,0 +1,11 @@
{
"main": "./RadioButtonGroup.vue",
"module": "./RadioButtonGroup.vue",
"types": "./RadioButtonGroup.d.ts",
"browser": {
"./sfc": "./RadioButtonGroup.vue"
},
"sideEffects": [
"*.vue"
]
}

View File

@ -0,0 +1,19 @@
/**
*
* FloatLabel visually integrates a label with its form element.
*
* [Live Demo](https://www.primevue.org/floatlabel/)
*
* @module radiobuttongroupstyle
*
*/
import type { BaseStyle } from '@primevue/core/base/style';
export enum RadioButtonGroupClasses {
/**
* Class name of the root element
*/
root = 'p-radiobutton-group'
}
export interface RadioButtonGroupStyle extends BaseStyle {}

View File

@ -0,0 +1,17 @@
import BaseStyle from '@primevue/core/base/style';
const theme = ({ dt }) => `
.p-radiobutton-group {
display: inline-flex;
}
`;
const classes = {
root: 'p-radiobutton-group p-component'
};
export default BaseStyle.extend({
name: 'radiobuttongroup',
theme,
classes
});

View File

@ -0,0 +1,6 @@
{
"main": "./RadioButtonGroupStyle.js",
"module": "./RadioButtonGroupStyle.js",
"types": "./RadioButtonGroupStyle.d.ts",
"sideEffects": false
}