403Webshell
Server IP : 80.87.202.40  /  Your IP : 216.73.216.169
Web Server : Apache
System : Linux rospirotorg.ru 5.14.0-539.el9.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Dec 5 22:26:13 UTC 2024 x86_64
User : bitrix ( 600)
PHP Version : 8.2.27
Disable Function : NONE
MySQL : OFF |  cURL : ON |  WGET : ON |  Perl : ON |  Python : OFF |  Sudo : ON |  Pkexec : ON
Directory :  /home/bitrix/ext_www/rospirotorg.ru/bitrix/js/ui/vue3/components/switcher/src/

Upload File :
current_dir [ Writeable] document_root [ Writeable]

 

Command :


[ Back ]     

Current File : /home/bitrix/ext_www/rospirotorg.ru/bitrix/js/ui/vue3/components/switcher/src/switcher.js
import { Dom } from 'main.core';
import { Switcher as UISwitcher, type SwitcherOptions } from 'ui.switcher';

/*
Example:

<Switcher
	:is-checked="myBoolData"
	@check="myBoolData = true"
	@uncheck="myBoolData = false"
	:options="{
		size: 'extra-small',
		color: 'green',
	}"
/>
 */

// @vue/component
export const Switcher = {
	name: 'Switcher',
	emits: ['check', 'uncheck'],
	props: {
		isChecked: {
			type: Boolean,
			required: true,
		},
		options: {
			/** @type SwitcherOptions */
			type: Object,
			default: {},
		},
	},
	switcher: null,
	mounted()
	{
		this.renderSwitcher();
	},
	watch: {
		isChecked(): void {
			this.switcher.check(this.isChecked, false);
		},
		options(newOptions, oldOptions): void {
			if (this.isOptionsEqual(newOptions, oldOptions))
			{
				return;
			}

			// re-render switcher since options has changed
			this.switcher = null;
			Dom.clean(this.$refs.container);
			this.renderSwitcher();
		},
	},
	methods: {
		renderSwitcher(): void {
			this.switcher = new UISwitcher(
				{
					...this.options,
					checked: this.isChecked,
					handlers: {
						// checked for when the switcher is made off and unchecked for when the switcher is made on
						// it looks like a bug, but I'm not sure
						checked: () => {
							// switch it back until the state is muted and we reactively change it to a new state
							this.switcher.check(this.isChecked, false);
							this.$emit('uncheck');
						},
						unchecked: () => {
							// switch it back until the state is muted and we reactively change it to a new state
							this.switcher.check(this.isChecked, false);
							this.$emit('check');
						},
					},
				},
			);

			this.switcher.renderTo(this.$refs.container);
		},
		isOptionsEqual(newOptions: SwitcherOptions, oldOptions: SwitcherOptions): boolean {
			if (Object.keys(newOptions).length !== Object.keys(oldOptions).length)
			{
				return false;
			}

			for (const [key, value] of Object.entries(newOptions))
			{
				if (!Object.hasOwn(oldOptions, key))
				{
					return false;
				}

				if (value !== oldOptions[key])
				{
					return false;
				}
			}

			for (const [key, value] of Object.entries(oldOptions))
			{
				if (!Object.hasOwn(newOptions, key))
				{
					return false;
				}

				if (value !== newOptions[key])
				{
					return false;
				}
			}

			return true;
		},
	},
	template: '<a ref="container"></a>',
};

Youez - 2016 - github.com/yon3zu
LinuXploit