HEX
Server: Apache/2.4.41 (Ubuntu)
System: Linux vm8 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: afleverb (1000)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: //var/www/drakkar_site/wp-content/themes/blocksy/static/js/options/options/ct-woocommerce-ratio.js
import { createElement, Component, useState } from '@wordpress/element'
import cls from 'classnames'
import { __, sprintf } from 'ct-i18n'
import Ratio from './ct-ratio'

import { useCustomizerValues } from '../../customizer/controls/customizer-values-context'

const WooCommerceRatio = ({
	value,
	onChange,
	onChangeFor,
	option,

	option: {
		croppingKey = 'woocommerce_archive_thumbnail_cropping',
		customWidthKey = 'woocommerce_archive_thumbnail_cropping_custom_width',
		customHeightKey = 'woocommerce_archive_thumbnail_cropping_custom_height',
	},

	...props
}) => {
	const [values, onChangeGlobalFor] = useCustomizerValues()

	return (
		<Ratio
			onChange={(val) => {
				let isCustom = val.indexOf('/') === -1
				let [width, height] = val.split(isCustom ? ':' : '/')

				if (val === 'original') {
					onChangeGlobalFor(croppingKey, 'uncropped')
					onChange('uncropped')
					return
				}

				onChange(isCustom ? 'custom' : 'predefined')
				onChangeGlobalFor(croppingKey, 'custom')

				onChangeGlobalFor(
					customHeightKey,
					parseFloat(height || '0') || 0
				)

				onChangeGlobalFor(customWidthKey, parseFloat(width || '0') || 0)
			}}
			value={
				value === 'uncropped'
					? 'original'
					: value === '1:1'
					? `1/1`
					: `${values[customWidthKey]}${
							value === 'custom' ? ':' : '/'
					  }${values[customHeightKey]}`
			}
			option={{
				...option,
				value: '1/1',
			}}
			onChangeFor={onChangeGlobalFor}
			{...props}
			values={values}
		/>
	)
}

WooCommerceRatio.ControlEnd = () => (
	<div
		className="ct-color-modal-wrapper"
		onMouseDown={(e) => e.stopPropagation()}
		onMouseUp={(e) => e.stopPropagation()}
	/>
)

export default WooCommerceRatio