first commit

This commit is contained in:
Stefan Hacker
2026-04-03 09:38:48 +02:00
commit 37ad745546
47450 changed files with 3120798 additions and 0 deletions
@@ -0,0 +1,3 @@
import * as React from 'react';
import type { ICheckboxProps } from './Checkbox.types';
export declare const CheckboxBase: React.FunctionComponent<ICheckboxProps>;
@@ -0,0 +1,101 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CheckboxBase = void 0;
var tslib_1 = require("tslib");
var React = require("react");
var react_hooks_1 = require("@fluentui/react-hooks");
var utilities_1 = require("@fluentui/utilities");
var Icon_1 = require("../Icon/Icon");
var getClassNames = (0, utilities_1.classNamesFunction)();
exports.CheckboxBase = React.forwardRef(function (props, forwardedRef) {
var disabled = props.disabled, required = props.required, inputProps = props.inputProps, name = props.name, ariaLabel = props.ariaLabel, ariaLabelledBy = props.ariaLabelledBy, ariaDescribedBy = props.ariaDescribedBy, ariaPositionInSet = props.ariaPositionInSet, ariaSetSize = props.ariaSetSize, title = props.title, checkmarkIconProps = props.checkmarkIconProps, styles = props.styles, theme = props.theme, className = props.className, _a = props.boxSide, boxSide = _a === void 0 ? 'start' : _a;
var id = (0, react_hooks_1.useId)('checkbox-', props.id);
var rootRef = React.useRef(null);
var mergedRootRefs = (0, react_hooks_1.useMergedRefs)(rootRef, forwardedRef);
var inputRef = React.useRef(null);
var _b = (0, react_hooks_1.useControllableValue)(props.checked, props.defaultChecked, props.onChange), isChecked = _b[0], setIsChecked = _b[1];
var _c = (0, react_hooks_1.useControllableValue)(props.indeterminate, props.defaultIndeterminate), isIndeterminate = _c[0], setIsIndeterminate = _c[1];
(0, utilities_1.useFocusRects)(rootRef);
useDebugWarning(props);
var classNames = getClassNames(styles, {
theme: theme,
className: className,
disabled: disabled,
indeterminate: isIndeterminate,
checked: isChecked,
reversed: boxSide !== 'start',
isUsingCustomLabelRender: !!props.onRenderLabel,
});
var onChange = React.useCallback(function (event) {
if (isIndeterminate) {
// If indeterminate, clicking the checkbox *only* removes the indeterminate state (or if
// controlled, lets the consumer know to change it by calling onChange). It doesn't
// change the checked state.
setIsChecked(!!isChecked, event);
setIsIndeterminate(false);
}
else {
setIsChecked(!isChecked, event);
}
}, [setIsChecked, setIsIndeterminate, isIndeterminate, isChecked]);
var defaultLabelRenderer = React.useCallback(function (checkboxProps) {
if (!checkboxProps) {
return null;
}
return checkboxProps.label ? (React.createElement("span", { className: classNames.text, title: checkboxProps.title }, checkboxProps.label)) : null;
}, [classNames.text]);
var setNativeIndeterminate = React.useCallback(function (indeterminate) {
if (!inputRef.current) {
return;
}
var value = !!indeterminate;
inputRef.current.indeterminate = value;
setIsIndeterminate(value);
}, [setIsIndeterminate]);
useComponentRef(props, isChecked, isIndeterminate, setNativeIndeterminate, inputRef);
React.useEffect(function () { return setNativeIndeterminate(isIndeterminate); }, [setNativeIndeterminate, isIndeterminate]);
var onRenderLabel = props.onRenderLabel || defaultLabelRenderer;
var ariaChecked = isIndeterminate
? 'mixed'
: undefined;
var mergedInputProps = tslib_1.__assign(tslib_1.__assign({ className: classNames.input, type: 'checkbox' }, inputProps), { checked: !!isChecked, disabled: disabled, required: required, name: name, id: id, title: title, onChange: onChange, 'aria-disabled': disabled, 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledBy, 'aria-describedby': ariaDescribedBy, 'aria-posinset': ariaPositionInSet, 'aria-setsize': ariaSetSize, 'aria-checked': ariaChecked });
return (React.createElement("div", { className: classNames.root, title: title, ref: mergedRootRefs },
React.createElement("input", tslib_1.__assign({}, mergedInputProps, { ref: inputRef, title: title, "data-ktp-execute-target": true })),
React.createElement("label", { className: classNames.label, htmlFor: id },
React.createElement("div", { className: classNames.checkbox, "data-ktp-target": true },
React.createElement(Icon_1.Icon, tslib_1.__assign({ iconName: "CheckMark" }, checkmarkIconProps, { className: classNames.checkmark }))),
onRenderLabel(props, defaultLabelRenderer))));
});
exports.CheckboxBase.displayName = 'CheckboxBase';
function useDebugWarning(props) {
if (process.env.NODE_ENV !== 'production') {
// eslint-disable-next-line react-hooks/rules-of-hooks -- build-time conditional
(0, react_hooks_1.useWarnings)({
name: 'Checkbox',
props: props,
mutuallyExclusive: {
checked: 'defaultChecked',
indeterminate: 'defaultIndeterminate',
},
});
}
}
function useComponentRef(props, isChecked, isIndeterminate, setIndeterminate, checkBoxRef) {
React.useImperativeHandle(props.componentRef, function () { return ({
get checked() {
return !!isChecked;
},
get indeterminate() {
return !!isIndeterminate;
},
set indeterminate(indeterminate) {
setIndeterminate(indeterminate);
},
focus: function () {
if (checkBoxRef.current) {
checkBoxRef.current.focus();
}
},
}); }, [checkBoxRef, isChecked, isIndeterminate, setIndeterminate]);
}
//# sourceMappingURL=Checkbox.base.js.map
File diff suppressed because one or more lines are too long
@@ -0,0 +1,3 @@
import * as React from 'react';
import type { ICheckboxProps } from './Checkbox.types';
export declare const Checkbox: React.FunctionComponent<ICheckboxProps>;
@@ -0,0 +1,8 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Checkbox = void 0;
var utilities_1 = require("@fluentui/utilities");
var Checkbox_base_1 = require("./Checkbox.base");
var Checkbox_styles_1 = require("./Checkbox.styles");
exports.Checkbox = (0, utilities_1.styled)(Checkbox_base_1.CheckboxBase, Checkbox_styles_1.getStyles, undefined, { scope: 'Checkbox' });
//# sourceMappingURL=Checkbox.js.map
@@ -0,0 +1 @@
{"version":3,"file":"Checkbox.js","sourceRoot":"../src/","sources":["components/Checkbox/Checkbox.tsx"],"names":[],"mappings":";;;AACA,iDAA6C;AAC7C,iDAA+C;AAC/C,qDAA8C;AAGjC,QAAA,QAAQ,GAA4C,IAAA,kBAAM,EAIrE,4BAAY,EAAE,2BAAS,EAAE,SAAS,EAAE,EAAE,KAAK,EAAE,UAAU,EAAE,CAAC,CAAC","sourcesContent":["import * as React from 'react';\nimport { styled } from '@fluentui/utilities';\nimport { CheckboxBase } from './Checkbox.base';\nimport { getStyles } from './Checkbox.styles';\nimport type { ICheckboxProps, ICheckboxStyleProps, ICheckboxStyles } from './Checkbox.types';\n\nexport const Checkbox: React.FunctionComponent<ICheckboxProps> = styled<\n ICheckboxProps,\n ICheckboxStyleProps,\n ICheckboxStyles\n>(CheckboxBase, getStyles, undefined, { scope: 'Checkbox' });\n"]}
@@ -0,0 +1,2 @@
import type { ICheckboxStyleProps, ICheckboxStyles } from './Checkbox.types';
export declare const getStyles: (props: ICheckboxStyleProps) => ICheckboxStyles;
@@ -0,0 +1,283 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getStyles = void 0;
var tslib_1 = require("tslib");
var style_utilities_1 = require("@fluentui/style-utilities");
var utilities_1 = require("@fluentui/utilities");
var GlobalClassNames = {
root: 'ms-Checkbox',
label: 'ms-Checkbox-label',
checkbox: 'ms-Checkbox-checkbox',
checkmark: 'ms-Checkbox-checkmark',
text: 'ms-Checkbox-text',
};
var MS_CHECKBOX_LABEL_SIZE = '20px';
var MS_CHECKBOX_TRANSITION_DURATION = '200ms';
var MS_CHECKBOX_TRANSITION_TIMING = 'cubic-bezier(.4, 0, .23, 1)';
var getStyles = function (props) {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t;
var className = props.className, theme = props.theme, reversed = props.reversed, checked = props.checked, disabled = props.disabled, isUsingCustomLabelRender = props.isUsingCustomLabelRender, indeterminate = props.indeterminate;
var semanticColors = theme.semanticColors, effects = theme.effects, palette = theme.palette, fonts = theme.fonts;
var classNames = (0, style_utilities_1.getGlobalClassNames)(GlobalClassNames, theme);
var checkmarkFontColor = semanticColors.inputForegroundChecked;
// TODO: after updating the semanticColors slots mapping this needs to be semanticColors.inputBorder
var checkmarkFontColorHovered = palette.neutralSecondary;
// TODO: after updating the semanticColors slots mapping this needs to be semanticColors.smallInputBorder
var checkboxBorderColor = palette.neutralPrimary;
var checkboxBorderIndeterminateColor = semanticColors.inputBackgroundChecked;
var checkboxBorderColorChecked = semanticColors.inputBackgroundChecked;
var checkboxBorderColorDisabled = semanticColors.disabledBodySubtext;
var checkboxBorderHoveredColor = semanticColors.inputBorderHovered;
var checkboxBorderIndeterminateHoveredColor = semanticColors.inputBackgroundCheckedHovered;
var checkboxBackgroundChecked = semanticColors.inputBackgroundChecked;
// TODO: after updating the semanticColors slots mapping the following 2 tokens need to be
// semanticColors.inputBackgroundCheckedHovered
var checkboxBackgroundCheckedHovered = semanticColors.inputBackgroundCheckedHovered;
var checkboxBorderColorCheckedHovered = semanticColors.inputBackgroundCheckedHovered;
var checkboxHoveredTextColor = semanticColors.inputTextHovered;
var checkboxBackgroundDisabledChecked = semanticColors.disabledBodySubtext;
var checkboxTextColor = semanticColors.bodyText;
var checkboxTextColorDisabled = semanticColors.disabledText;
var indeterminateDotStyles = [
(_a = {
content: '""',
borderRadius: effects.roundedCorner2,
position: 'absolute',
width: 10,
height: 10,
top: 4,
left: 4,
boxSizing: 'border-box',
borderWidth: 5,
borderStyle: 'solid',
borderColor: disabled ? checkboxBorderColorDisabled : checkboxBorderIndeterminateColor,
transitionProperty: 'border-width, border, border-color',
transitionDuration: MS_CHECKBOX_TRANSITION_DURATION,
transitionTimingFunction: MS_CHECKBOX_TRANSITION_TIMING
},
_a[style_utilities_1.HighContrastSelector] = {
borderColor: 'WindowText',
},
_a),
];
return {
root: [
classNames.root,
{
position: 'relative',
display: 'flex',
},
reversed && 'reversed',
checked && 'is-checked',
!disabled && 'is-enabled',
disabled && 'is-disabled',
!disabled && [
!checked && (_b = {},
_b[":hover .".concat(classNames.checkbox)] = (_c = {
borderColor: checkboxBorderHoveredColor
},
_c[style_utilities_1.HighContrastSelector] = {
borderColor: 'Highlight',
},
_c),
_b[":focus .".concat(classNames.checkbox)] = { borderColor: checkboxBorderHoveredColor },
_b[":hover .".concat(classNames.checkmark)] = (_d = {
color: checkmarkFontColorHovered,
opacity: '1'
},
_d[style_utilities_1.HighContrastSelector] = {
color: 'Highlight',
},
_d),
_b),
checked &&
!indeterminate && (_e = {},
_e[":hover .".concat(classNames.checkbox)] = {
background: checkboxBackgroundCheckedHovered,
borderColor: checkboxBorderColorCheckedHovered,
},
_e[":focus .".concat(classNames.checkbox)] = {
background: checkboxBackgroundCheckedHovered,
borderColor: checkboxBorderColorCheckedHovered,
},
_e[style_utilities_1.HighContrastSelector] = (_f = {},
_f[":hover .".concat(classNames.checkbox)] = {
background: 'Highlight',
borderColor: 'Highlight',
},
_f[":focus .".concat(classNames.checkbox)] = {
background: 'Highlight',
},
_f[":focus:hover .".concat(classNames.checkbox)] = {
background: 'Highlight',
},
_f[":focus:hover .".concat(classNames.checkmark)] = {
color: 'Window',
},
_f[":hover .".concat(classNames.checkmark)] = {
color: 'Window',
},
_f),
_e),
indeterminate && (_g = {},
_g[":hover .".concat(classNames.checkbox, ", :hover .").concat(classNames.checkbox, ":after")] = (_h = {
borderColor: checkboxBorderIndeterminateHoveredColor
},
_h[style_utilities_1.HighContrastSelector] = {
borderColor: 'WindowText',
},
_h),
_g[":focus .".concat(classNames.checkbox)] = {
borderColor: checkboxBorderIndeterminateHoveredColor,
},
_g[":hover .".concat(classNames.checkmark)] = {
opacity: '0',
},
_g),
(_j = {},
_j[":hover .".concat(classNames.text, ", :focus .").concat(classNames.text)] = (_k = {
color: checkboxHoveredTextColor
},
_k[style_utilities_1.HighContrastSelector] = {
color: disabled ? 'GrayText' : 'WindowText',
},
_k),
_j),
],
className,
],
input: (_l = {
position: 'absolute',
background: 'none',
opacity: 0
},
// eslint-disable-next-line @fluentui/max-len
_l[".".concat(utilities_1.IsFocusVisibleClassName, " &:focus + label::before, :host(.").concat(utilities_1.IsFocusVisibleClassName, ") &:focus + label::before")] = (_m = {
outline: '1px solid ' + theme.palette.neutralSecondary,
outlineOffset: '2px'
},
_m[style_utilities_1.HighContrastSelector] = {
outline: '1px solid WindowText',
},
_m),
_l),
label: [
classNames.label,
theme.fonts.medium,
{
display: 'flex',
alignItems: isUsingCustomLabelRender ? 'center' : 'flex-start',
cursor: disabled ? 'default' : 'pointer',
position: 'relative',
userSelect: 'none',
},
reversed && {
flexDirection: 'row-reverse',
justifyContent: 'flex-end',
},
{
'&::before': {
position: 'absolute',
left: 0,
right: 0,
top: 0,
bottom: 0,
content: '""',
pointerEvents: 'none',
},
},
],
checkbox: [
classNames.checkbox,
(_o = {
position: 'relative',
display: 'flex',
flexShrink: 0,
alignItems: 'center',
justifyContent: 'center',
height: MS_CHECKBOX_LABEL_SIZE,
width: MS_CHECKBOX_LABEL_SIZE,
border: "1px solid ".concat(checkboxBorderColor),
borderRadius: effects.roundedCorner2,
boxSizing: 'border-box',
transitionProperty: 'background, border, border-color',
transitionDuration: MS_CHECKBOX_TRANSITION_DURATION,
transitionTimingFunction: MS_CHECKBOX_TRANSITION_TIMING,
/* in case the icon is bigger than the box */
overflow: 'hidden',
':after': indeterminate ? indeterminateDotStyles : null
},
_o[style_utilities_1.HighContrastSelector] = tslib_1.__assign({ borderColor: 'WindowText' }, (0, style_utilities_1.getHighContrastNoAdjustStyle)()),
_o),
indeterminate && {
borderColor: checkboxBorderIndeterminateColor,
},
!reversed
? // This margin on the checkbox is for backwards compat. Notably it has the effect where a customRender
// is used, there will be only a 4px margin from checkbox to label. The label by default would have
// another 4px margin for a total of 8px margin between checkbox and label. We don't combine the two
// (and move it into the text) to not incur a breaking change for everyone using custom render atm.
{
marginRight: 4,
}
: {
marginLeft: 4,
},
!disabled &&
!indeterminate &&
checked && (_p = {
background: checkboxBackgroundChecked,
borderColor: checkboxBorderColorChecked
},
_p[style_utilities_1.HighContrastSelector] = {
background: 'Highlight',
borderColor: 'Highlight',
},
_p),
disabled && (_q = {
borderColor: checkboxBorderColorDisabled
},
_q[style_utilities_1.HighContrastSelector] = {
borderColor: 'GrayText',
},
_q),
checked &&
disabled && (_r = {
background: checkboxBackgroundDisabledChecked,
borderColor: checkboxBorderColorDisabled
},
_r[style_utilities_1.HighContrastSelector] = {
background: 'Window',
},
_r),
],
checkmark: [
classNames.checkmark,
(_s = {
opacity: checked && !indeterminate ? '1' : '0',
color: checkmarkFontColor
},
_s[style_utilities_1.HighContrastSelector] = tslib_1.__assign({ color: disabled ? 'GrayText' : 'Window' }, (0, style_utilities_1.getHighContrastNoAdjustStyle)()),
_s),
],
text: [
classNames.text,
(_t = {
color: disabled ? checkboxTextColorDisabled : checkboxTextColor,
fontSize: fonts.medium.fontSize,
lineHeight: '20px'
},
_t[style_utilities_1.HighContrastSelector] = tslib_1.__assign({ color: disabled ? 'GrayText' : 'WindowText' }, (0, style_utilities_1.getHighContrastNoAdjustStyle)()),
_t),
!reversed
? {
marginLeft: 4,
}
: {
marginRight: 4,
},
],
};
};
exports.getStyles = getStyles;
//# sourceMappingURL=Checkbox.styles.js.map
File diff suppressed because one or more lines are too long
@@ -0,0 +1,179 @@
import * as React from 'react';
import type { IStyle, ITheme } from '@fluentui/style-utilities';
import type { IRefObject, IRenderFunction, IStyleFunctionOrObject } from '@fluentui/utilities';
import type { IIconProps } from '../Icon/Icon.types';
/**
* Checkbox class interface.
* {@docCategory Checkbox}
*/
export interface ICheckbox {
/** Gets the current indeterminate state. */
indeterminate: boolean;
/** Gets the current checked state. */
checked: boolean;
/** Sets focus to the checkbox. */
focus: () => void;
}
/**
* Checkbox properties.
* {@docCategory Checkbox}
*/
export interface ICheckboxProps extends React.RefAttributes<HTMLDivElement> {
/**
* Optional callback to access the `ICheckbox` interface. Use this instead of `ref` for accessing
* the public methods and properties of the component.
*/
componentRef?: IRefObject<ICheckbox>;
/**
* Class name to provide on the root element, in addition to the `ms-Checkbox` class.
*/
className?: string;
/**
* Checked state. Mutually exclusive with `defaultChecked`. Use this if you control the checked state at a higher
* level and plan to pass in the correct value based on handling `onChange` events and re-rendering.
*/
checked?: boolean;
/**
* Default checked state. Mutually exclusive with `checked`. Use this if you want an uncontrolled component,
* meaning the Checkbox instance maintains its own state.
*/
defaultChecked?: boolean;
/**
* Label to display next to the checkbox.
*/
label?: string;
/**
* Disabled state of the checkbox.
*/
disabled?: boolean;
/**
* Required state of the checkbox.
*/
required?: boolean;
/**
* Callback that is called when the checked value has changed.
*/
onChange?: (ev?: React.FormEvent<HTMLElement | HTMLInputElement>, checked?: boolean) => void;
/**
* Title text applied to the root element and the hidden checkbox input.
* (Use `label` instead for the visible label.)
*/
title?: string;
/**
* ID for the checkbox input.
*/
id?: string;
/**
* Name for the checkbox input. This is intended for use with forms and NOT displayed in the UI.
*/
name?: string;
/**
* Optional props that will be applied to the input element, *before* other props are applied.
* Note that if you provide, for example, `disabled` as well as `inputProps.disabled`, the
* top-level prop (`disabled` in this case) will take precedence.
*
* Including `data-*` props in `inputProps` is supported but currently requires casting since
* TS 3.7 doesn't provide a way to allow all keys with a certain prefix.
*/
inputProps?: React.ButtonHTMLAttributes<HTMLElement | HTMLButtonElement>;
/**
* Determines whether the checkbox should be shown before the label (`start`) or after (`end`).
* @defaultvalue 'start'
*/
boxSide?: 'start' | 'end';
/**
* Theme provided by HOC.
*/
theme?: ITheme;
/**
* Accessible label for the checkbox.
*/
ariaLabel?: string;
/**
* ID for element that contains label information for the checkbox.
*/
ariaLabelledBy?: string;
/**
* ID for element that provides extended information for the checkbox.
*/
ariaDescribedBy?: string;
/**
* The position in the parent set (if in a set) for `aria-posinset`.
*/
ariaPositionInSet?: number;
/**
* The total size of the parent set (if in a set) for `aria-setsize`.
*/
ariaSetSize?: number;
/**
* Call to provide customized styling that will layer on top of the variant rules.
*/
styles?: IStyleFunctionOrObject<ICheckboxStyleProps, ICheckboxStyles>;
/**
* Custom render function for the label.
*/
onRenderLabel?: IRenderFunction<ICheckboxProps>;
/**
* Custom icon props for the check mark rendered by the checkbox
*/
checkmarkIconProps?: IIconProps;
/**
* Optional controlled indeterminate visual state for checkbox. Setting indeterminate state takes visual precedence
* over `checked` or `defaultChecked` props given but does not affect checked state.
*
* This should not be a toggleable state. On load, the checkbox will receive indeterminate visual state.
* After the first user click, your supplied `onChange` callback should remove the indeterminate state
* (without modifying the checked state), exposing the true state of the checkbox.
*/
indeterminate?: boolean;
/**
* Optional uncontrolled indeterminate visual state for checkbox. Setting indeterminate state takes visual precedence
* over `checked` or `defaultChecked` props given but does not affect checked state.
*
* This should not be a toggleable state. On load, the checkbox will receive indeterminate visual state.
* After the user's first click, it will be removed, exposing the true state of the checkbox.
*/
defaultIndeterminate?: boolean;
}
/**
* {@docCategory Checkbox}
*/
export interface ICheckboxStyleProps {
theme: ITheme;
className?: string;
disabled?: boolean;
checked?: boolean;
reversed?: boolean;
indeterminate?: boolean;
isUsingCustomLabelRender: boolean;
}
/**
* {@docCategory Checkbox}
*/
export interface ICheckboxStyles {
/**
* Style for the root element (a button) of the checkbox component in the default enabled/unchecked state.
*/
root?: IStyle;
/**
* INTERNAL: This is mostly an internal implementation detail which you should avoid styling.
* This refers to the `<input type="checkbox">` element that is typically hidden and not rendered on screen.
*/
input?: IStyle;
/**
* Style for the label part (contains the customized checkbox + text) when enabled.
*/
label?: IStyle;
/**
* Style for checkbox in its default unchecked/enabled state.
*/
checkbox?: IStyle;
/**
* Style for the checkmark in the default enabled/unchecked state.
*/
checkmark?: IStyle;
/**
* Style for text appearing with the checkbox in its default enabled state.
*/
text?: IStyle;
}
@@ -0,0 +1,3 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=Checkbox.types.js.map
File diff suppressed because one or more lines are too long
@@ -0,0 +1,3 @@
export * from './Checkbox';
export * from './Checkbox.base';
export * from './Checkbox.types';
@@ -0,0 +1,7 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
tslib_1.__exportStar(require("./Checkbox"), exports);
tslib_1.__exportStar(require("./Checkbox.base"), exports);
tslib_1.__exportStar(require("./Checkbox.types"), exports);
//# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"../src/","sources":["components/Checkbox/index.ts"],"names":[],"mappings":";;;AAAA,qDAA2B;AAC3B,0DAAgC;AAChC,2DAAiC","sourcesContent":["export * from './Checkbox';\nexport * from './Checkbox.base';\nexport * from './Checkbox.types';\n"]}