Disable 'invert every other symbol' if needed.
rodzic
dc13207b4d
commit
24eead10f8
|
@ -1,17 +1,20 @@
|
||||||
|
import classNames from "classnames";
|
||||||
import React from "react";
|
import React from "react";
|
||||||
|
|
||||||
type CheckboxProps = {
|
type CheckboxProps = {
|
||||||
label: string;
|
label: string;
|
||||||
onChange: (value: boolean) => void;
|
onChange: (value: boolean) => void;
|
||||||
value: boolean;
|
value: boolean;
|
||||||
|
disabled?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const Checkbox: React.FC<CheckboxProps> = (props) => {
|
export const Checkbox: React.FC<CheckboxProps> = (props) => {
|
||||||
return (
|
return (
|
||||||
<label className="checkbox">
|
<label className={classNames("checkbox", { disabled: props.disabled })}>
|
||||||
<input
|
<input
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
checked={props.value}
|
checked={props.value}
|
||||||
|
disabled={props.disabled}
|
||||||
onChange={(e) => props.onChange(e.target.checked)}
|
onChange={(e) => props.onChange(e.target.checked)}
|
||||||
/>{" "}
|
/>{" "}
|
||||||
{props.label}
|
{props.label}
|
||||||
|
|
|
@ -11,7 +11,7 @@ import {
|
||||||
swapColors,
|
swapColors,
|
||||||
} from "./svg-symbol";
|
} from "./svg-symbol";
|
||||||
import { svgRotate, SvgTransform, svgTranslate } from "./svg-transform";
|
import { svgRotate, SvgTransform, svgTranslate } from "./svg-transform";
|
||||||
import { range } from "./util";
|
import { isEvenNumber, range } from "./util";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the anchor point of the given symbol; if it doesn't have
|
* Returns the anchor point of the given symbol; if it doesn't have
|
||||||
|
@ -38,10 +38,6 @@ export type MandalaCircleParams = {
|
||||||
|
|
||||||
export type MandalaCircleProps = MandalaCircleParams & SvgSymbolContext;
|
export type MandalaCircleProps = MandalaCircleParams & SvgSymbolContext;
|
||||||
|
|
||||||
function isEvenNumber(value: number) {
|
|
||||||
return value % 2 === 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const MandalaCircle: React.FC<MandalaCircleProps> = (props) => {
|
export const MandalaCircle: React.FC<MandalaCircleProps> = (props) => {
|
||||||
const degreesPerItem = 360 / props.numSymbols;
|
const degreesPerItem = 360 / props.numSymbols;
|
||||||
const { translation, rotation } = getAttachmentTransforms(
|
const { translation, rotation } = getAttachmentTransforms(
|
||||||
|
|
|
@ -11,7 +11,7 @@ import {
|
||||||
import { VocabularyWidget } from "../vocabulary-widget";
|
import { VocabularyWidget } from "../vocabulary-widget";
|
||||||
import { svgRotate, svgScale, SvgTransform } from "../svg-transform";
|
import { svgRotate, svgScale, SvgTransform } from "../svg-transform";
|
||||||
import { SvgVocabulary } from "../svg-vocabulary";
|
import { SvgVocabulary } from "../svg-vocabulary";
|
||||||
import { NumericRange } from "../util";
|
import { isEvenNumber, NumericRange } from "../util";
|
||||||
import { Random } from "../random";
|
import { Random } from "../random";
|
||||||
import { Checkbox } from "../checkbox";
|
import { Checkbox } from "../checkbox";
|
||||||
import {
|
import {
|
||||||
|
@ -186,6 +186,7 @@ const ExtendedMandalaCircleParamsWidget: React.FC<{
|
||||||
/>
|
/>
|
||||||
<Checkbox
|
<Checkbox
|
||||||
label="Invert every other symbol (applies only to circles with an even number of symbols)"
|
label="Invert every other symbol (applies only to circles with an even number of symbols)"
|
||||||
|
disabled={!isEvenNumber(value.numSymbols)}
|
||||||
value={value.invertEveryOtherSymbol}
|
value={value.invertEveryOtherSymbol}
|
||||||
onChange={(invertEveryOtherSymbol) =>
|
onChange={(invertEveryOtherSymbol) =>
|
||||||
onChange({ ...value, invertEveryOtherSymbol })
|
onChange({ ...value, invertEveryOtherSymbol })
|
||||||
|
|
|
@ -70,3 +70,8 @@ export function slugify(text: string) {
|
||||||
.replace(/^-+/, "") // Trim - from start of text
|
.replace(/^-+/, "") // Trim - from start of text
|
||||||
.replace(/-+$/, ""); // Trim - from end of text
|
.replace(/-+$/, ""); // Trim - from end of text
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Returns whether the given number is even (as opposed to odd). */
|
||||||
|
export function isEvenNumber(value: number) {
|
||||||
|
return value % 2 === 0;
|
||||||
|
}
|
||||||
|
|
Ładowanie…
Reference in New Issue