123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227 |
- import { withDirectives as _withDirectives, resolveDirective as _resolveDirective, createVNode as _createVNode } from "vue";
- // Styles
- import "./VBtn.css";
- // Components
- import { VBtnToggleSymbol } from "../VBtnToggle/VBtnToggle.mjs";
- import { VDefaultsProvider } from "../VDefaultsProvider/index.mjs";
- import { VIcon } from "../VIcon/index.mjs";
- import { VProgressCircular } from "../VProgressCircular/index.mjs"; // Composables
- import { makeBorderProps, useBorder } from "../../composables/border.mjs";
- import { makeComponentProps } from "../../composables/component.mjs";
- import { makeDensityProps, useDensity } from "../../composables/density.mjs";
- import { makeDimensionProps, useDimension } from "../../composables/dimensions.mjs";
- import { makeElevationProps, useElevation } from "../../composables/elevation.mjs";
- import { makeGroupItemProps, useGroupItem } from "../../composables/group.mjs";
- import { IconValue } from "../../composables/icons.mjs";
- import { makeLoaderProps, useLoader } from "../../composables/loader.mjs";
- import { makeLocationProps, useLocation } from "../../composables/location.mjs";
- import { makePositionProps, usePosition } from "../../composables/position.mjs";
- import { makeRoundedProps, useRounded } from "../../composables/rounded.mjs";
- import { makeRouterProps, useLink } from "../../composables/router.mjs";
- import { useSelectLink } from "../../composables/selectLink.mjs";
- import { makeSizeProps, useSize } from "../../composables/size.mjs";
- import { makeTagProps } from "../../composables/tag.mjs";
- import { makeThemeProps, provideTheme } from "../../composables/theme.mjs";
- import { genOverlays, makeVariantProps, useVariant } from "../../composables/variant.mjs"; // Directives
- import { Ripple } from "../../directives/ripple/index.mjs"; // Utilities
- import { computed } from 'vue';
- import { genericComponent, propsFactory, useRender } from "../../util/index.mjs"; // Types
- export const makeVBtnProps = propsFactory({
- active: {
- type: Boolean,
- default: undefined
- },
- symbol: {
- type: null,
- default: VBtnToggleSymbol
- },
- flat: Boolean,
- icon: [Boolean, String, Function, Object],
- prependIcon: IconValue,
- appendIcon: IconValue,
- block: Boolean,
- stacked: Boolean,
- ripple: {
- type: [Boolean, Object],
- default: true
- },
- text: String,
- ...makeBorderProps(),
- ...makeComponentProps(),
- ...makeDensityProps(),
- ...makeDimensionProps(),
- ...makeElevationProps(),
- ...makeGroupItemProps(),
- ...makeLoaderProps(),
- ...makeLocationProps(),
- ...makePositionProps(),
- ...makeRoundedProps(),
- ...makeRouterProps(),
- ...makeSizeProps(),
- ...makeTagProps({
- tag: 'button'
- }),
- ...makeThemeProps(),
- ...makeVariantProps({
- variant: 'elevated'
- })
- }, 'VBtn');
- export const VBtn = genericComponent()({
- name: 'VBtn',
- directives: {
- Ripple
- },
- props: makeVBtnProps(),
- emits: {
- 'group:selected': val => true
- },
- setup(props, _ref) {
- let {
- attrs,
- slots
- } = _ref;
- const {
- themeClasses
- } = provideTheme(props);
- const {
- borderClasses
- } = useBorder(props);
- const {
- colorClasses,
- colorStyles,
- variantClasses
- } = useVariant(props);
- const {
- densityClasses
- } = useDensity(props);
- const {
- dimensionStyles
- } = useDimension(props);
- const {
- elevationClasses
- } = useElevation(props);
- const {
- loaderClasses
- } = useLoader(props);
- const {
- locationStyles
- } = useLocation(props);
- const {
- positionClasses
- } = usePosition(props);
- const {
- roundedClasses
- } = useRounded(props);
- const {
- sizeClasses,
- sizeStyles
- } = useSize(props);
- const group = useGroupItem(props, props.symbol, false);
- const link = useLink(props, attrs);
- const isActive = computed(() => {
- if (props.active !== undefined) {
- return props.active;
- }
- if (link.isLink.value) {
- return link.isActive?.value;
- }
- return group?.isSelected.value;
- });
- const isDisabled = computed(() => group?.disabled.value || props.disabled);
- const isElevated = computed(() => {
- return props.variant === 'elevated' && !(props.disabled || props.flat || props.border);
- });
- const valueAttr = computed(() => {
- if (props.value === undefined) return undefined;
- return Object(props.value) === props.value ? JSON.stringify(props.value, null, 0) : props.value;
- });
- function onClick(e) {
- if (isDisabled.value || link.isLink.value && (e.metaKey || e.ctrlKey || e.shiftKey || e.button !== 0 || attrs.target === '_blank')) return;
- link.navigate?.(e);
- group?.toggle();
- }
- useSelectLink(link, group?.select);
- useRender(() => {
- const Tag = link.isLink.value ? 'a' : props.tag;
- const hasPrepend = !!(props.prependIcon || slots.prepend);
- const hasAppend = !!(props.appendIcon || slots.append);
- const hasIcon = !!(props.icon && props.icon !== true);
- const hasColor = group?.isSelected.value && (!link.isLink.value || link.isActive?.value) || !group || link.isActive?.value;
- return _withDirectives(_createVNode(Tag, {
- "type": Tag === 'a' ? undefined : 'button',
- "class": ['v-btn', group?.selectedClass.value, {
- 'v-btn--active': isActive.value,
- 'v-btn--block': props.block,
- 'v-btn--disabled': isDisabled.value,
- 'v-btn--elevated': isElevated.value,
- 'v-btn--flat': props.flat,
- 'v-btn--icon': !!props.icon,
- 'v-btn--loading': props.loading,
- 'v-btn--stacked': props.stacked
- }, themeClasses.value, borderClasses.value, hasColor ? colorClasses.value : undefined, densityClasses.value, elevationClasses.value, loaderClasses.value, positionClasses.value, roundedClasses.value, sizeClasses.value, variantClasses.value, props.class],
- "style": [hasColor ? colorStyles.value : undefined, dimensionStyles.value, locationStyles.value, sizeStyles.value, props.style],
- "disabled": isDisabled.value || undefined,
- "href": link.href.value,
- "onClick": onClick,
- "value": valueAttr.value
- }, {
- default: () => [genOverlays(true, 'v-btn'), !props.icon && hasPrepend && _createVNode("span", {
- "key": "prepend",
- "class": "v-btn__prepend"
- }, [!slots.prepend ? _createVNode(VIcon, {
- "key": "prepend-icon",
- "icon": props.prependIcon
- }, null) : _createVNode(VDefaultsProvider, {
- "key": "prepend-defaults",
- "disabled": !props.prependIcon,
- "defaults": {
- VIcon: {
- icon: props.prependIcon
- }
- }
- }, slots.prepend)]), _createVNode("span", {
- "class": "v-btn__content",
- "data-no-activator": ""
- }, [!slots.default && hasIcon ? _createVNode(VIcon, {
- "key": "content-icon",
- "icon": props.icon
- }, null) : _createVNode(VDefaultsProvider, {
- "key": "content-defaults",
- "disabled": !hasIcon,
- "defaults": {
- VIcon: {
- icon: props.icon
- }
- }
- }, {
- default: () => [slots.default?.() ?? props.text]
- })]), !props.icon && hasAppend && _createVNode("span", {
- "key": "append",
- "class": "v-btn__append"
- }, [!slots.append ? _createVNode(VIcon, {
- "key": "append-icon",
- "icon": props.appendIcon
- }, null) : _createVNode(VDefaultsProvider, {
- "key": "append-defaults",
- "disabled": !props.appendIcon,
- "defaults": {
- VIcon: {
- icon: props.appendIcon
- }
- }
- }, slots.append)]), !!props.loading && _createVNode("span", {
- "key": "loader",
- "class": "v-btn__loader"
- }, [slots.loader?.() ?? _createVNode(VProgressCircular, {
- "color": typeof props.loading === 'boolean' ? undefined : props.loading,
- "indeterminate": true,
- "size": "23",
- "width": "2"
- }, null)])]
- }), [[_resolveDirective("ripple"), !isDisabled.value && props.ripple, null]]);
- });
- return {};
- }
- });
- //# sourceMappingURL=VBtn.mjs.map
|