Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(react-swatch-picker): fixes after bug bash #31097

Merged
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,17 @@ export const DefaultRTL = getStoryVariant(Default, RTL);
export const Size = () => (
<>
<h3>Colors</h3>
<SampleSwatchPickerColors size="extraSmall" />
<SampleSwatchPickerColors size="extra-small" />
<SampleSwatchPickerColors size="small" />
<SampleSwatchPickerColors size="medium" />
<SampleSwatchPickerColors size="large" />
<h3>Images</h3>
<SampleSwatchPickerImages size="extraSmall" />
<SampleSwatchPickerImages size="extra-small" />
<SampleSwatchPickerImages size="small" />
<SampleSwatchPickerImages size="medium" />
<SampleSwatchPickerImages size="large" />
<h3>Grid layout</h3>
<SampleSwatchPickerGrid size="extraSmall" />
<SampleSwatchPickerGrid size="extra-small" />
<SampleSwatchPickerGrid size="small" />
<SampleSwatchPickerGrid size="medium" />
<SampleSwatchPickerGrid size="large" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "minor",
"comment": "fix: api changes and fixes",
ValentinaKozlova marked this conversation as resolved.
Show resolved Hide resolved
"packageName": "@fluentui/react-swatch-picker-preview",
"email": "vkozlova@microsoft.com",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,6 @@ export const SwatchPicker: ForwardRefComponent<SwatchPickerProps>;
// @public (undocumented)
export const swatchPickerClassNames: SlotClassNames<SwatchPickerSlots>;

// @public (undocumented)
export const swatchPickerCSSVars: {
gridGap: string;
};

// @public (undocumented)
export type SwatchPickerGridProps = {
items: SwatchProps[];
Expand All @@ -139,7 +134,7 @@ export type SwatchPickerProps = ComponentProps<SwatchPickerSlots> & {
layout?: 'row' | 'grid';
onSelectionChange?: EventHandler<SwatchPickerOnSelectionChangeData>;
selectedValue?: string;
size?: 'extraSmall' | 'small' | 'medium' | 'large';
size?: 'extra-small' | 'small' | 'medium' | 'large';
shape?: 'rounded' | 'square' | 'circular';
spacing?: 'small' | 'medium';
};
Expand All @@ -159,7 +154,7 @@ export type SwatchPickerRowSlots = {
};

// @public
export type SwatchPickerRowState = ComponentState<SwatchPickerRowSlots>;
export type SwatchPickerRowState = ComponentState<SwatchPickerRowSlots> & Pick<SwatchPickerProps, 'spacing'>;

// @public (undocumented)
export type SwatchPickerSlots = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ const useStyles = makeStyles({
});

const useSizeStyles = makeStyles({
extraSmall: {
'extra-small': {
width: '20px',
height: '20px',
},
Expand Down Expand Up @@ -136,7 +136,7 @@ const useIconStyles = makeStyles({
display: 'flex',
alignSelf: 'center',
},
extraSmall: {
'extra-small': {
fontSize: '16px',
},
small: {
Expand All @@ -160,13 +160,13 @@ export const useColorSwatchStyles_unstable = (state: ColorSwatchState): ColorSwa
const shapeStyles = useShapeStyles();
const iconStyles = useIconStyles();

const size = state.size ?? 'medium';
const { size = 'medium', shape = 'square' } = state;

state.root.className = mergeClasses(
colorSwatchClassNames.root,
resetStyles,
sizeStyles[size],
shapeStyles[state.shape ?? 'square'],
shapeStyles[shape],
state.selected && styles.selected,
state.disabled && styles.disabled,
state.root.className,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ describe('EmptySwatch', () => {
expect(result.container).toMatchInlineSnapshot(`
<div>
<button
aria-checked="false"
class="fui-EmptySwatch"
role="radio"
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export const useEmptySwatch_unstable = (
const isGrid = useSwatchPickerContextValue_unstable(ctx => ctx.isGrid);

const role = isGrid ? 'gridcell' : 'radio';
const a11yProps = isGrid ? {} : { 'aria-checked': false };
Hotell marked this conversation as resolved.
Show resolved Hide resolved
return {
components: {
root: 'button',
Expand All @@ -30,6 +31,7 @@ export const useEmptySwatch_unstable = (
getIntrinsicElementProps('button', {
ref,
role,
...a11yProps,
...rest,
}),
{ elementType: 'button' },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const useStyles = makeResetStyles({
});

const useSizeStyles = makeStyles({
extraSmall: {
'extra-small': {
width: '20px',
height: '20px',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ const useStylesSelected = makeStyles({
});

const useSizeStyles = makeStyles({
extraSmall: {
'extra-small': {
width: '20px',
height: '20px',
},
Expand Down Expand Up @@ -120,11 +120,13 @@ export const useImageSwatchStyles_unstable = (state: ImageSwatchState): ImageSwa
const sizeStyles = useSizeStyles();
const shapeStyles = useShapeStyles();

const { size = 'medium', shape = 'square' } = state;

state.root.className = mergeClasses(
imageSwatchClassNames.root,
styles,
sizeStyles[state.size ?? 'medium'],
shapeStyles[state.shape ?? 'square'],
sizeStyles[size],
shapeStyles[shape],
state.selected && selectedStyles.selected,
state.root.className,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ describe('SwatchPicker', () => {
class="fui-SwatchPicker"
data-tabster="{\\"mover\\":{\\"cyclic\\":true,\\"direction\\":0,\\"memorizeCurrent\\":true}}"
role="radiogroup"
style="--fui-SwatchPicker--gridGap: 4px;"
>
<button
aria-checked="false"
Expand Down Expand Up @@ -70,6 +69,7 @@ describe('SwatchPicker', () => {
style="background-image: url(path/img.png);"
/>
<button
aria-checked="false"
class="fui-EmptySwatch"
role="radio"
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export type SwatchPickerProps = ComponentProps<SwatchPickerSlots> & {
* Swatch size
* @defaultvalue 'medium'
*/
size?: 'extraSmall' | 'small' | 'medium' | 'large';
size?: 'extra-small' | 'small' | 'medium' | 'large';

/**
* Swatch shape
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,6 @@ import * as React from 'react';
import { getIntrinsicElementProps, useControllableState, useEventCallback, slot } from '@fluentui/react-utilities';
import type { SwatchPickerProps, SwatchPickerState } from './SwatchPicker.types';
import { useArrowNavigationGroup } from '@fluentui/react-tabster';
import { swatchPickerCSSVars } from './useSwatchPickerStyles.styles';

const { gridGap } = swatchPickerCSSVars;

export const spacingMap = {
small: '2px',
medium: '4px',
};

/**
* Create the state required to render SwatchPicker.
Expand Down Expand Up @@ -61,10 +53,6 @@ export const useSwatchPicker_unstable = (
role,
...focusAttributes,
...rest,
style: {
[gridGap]: spacingMap[spacing],
...style,
},
}),
{ elementType: 'div' },
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,6 @@ export const swatchPickerClassNames: SlotClassNames<SwatchPickerSlots> = {
root: 'fui-SwatchPicker',
};

export const swatchPickerCSSVars = {
Hotell marked this conversation as resolved.
Show resolved Hide resolved
gridGap: `--fui-SwatchPicker--gridGap`,
};

const { gridGap } = swatchPickerCSSVars;

/**
* Styles for the root slot
*/
Expand All @@ -22,11 +16,15 @@ const useStyles = makeStyles({
},
row: {
flexDirection: 'row',
columnGap: `var(${gridGap})`,
},
grid: {
flexDirection: 'column',
rowGap: `var(${gridGap})`,
},
spacingSmall: {
...shorthands.gap('2px'),
},
spacingMedium: {
...shorthands.gap('4px'),
},
});

Expand All @@ -36,7 +34,15 @@ const useStyles = makeStyles({
export const useSwatchPickerStyles_unstable = (state: SwatchPickerState): SwatchPickerState => {
const styles = useStyles();
const layoutStyle = state.isGrid ? styles.grid : styles.row;
state.root.className = mergeClasses(swatchPickerClassNames.root, styles.root, layoutStyle, state.root.className);

const spacingStyle = state.spacing === 'small' ? styles.spacingSmall : styles.spacingMedium;
state.root.className = mergeClasses(
swatchPickerClassNames.root,
styles.root,
layoutStyle,
spacingStyle,
state.root.className,
);

return state;
};
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ describe('SwatchPickerRow', () => {
<div
class="fui-SwatchPickerRow"
role="row"
style="--fui-SwatchPicker--rowGap: 4px;"
>
Default SwatchPickerRow
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { ComponentProps, ComponentState, Slot } from '@fluentui/react-utilities';
import type { SwatchPickerProps } from '../SwatchPicker/SwatchPicker.types';

export type SwatchPickerRowSlots = {
root: Slot<'div'>;
Expand All @@ -12,4 +13,4 @@ export type SwatchPickerRowProps = ComponentProps<SwatchPickerRowSlots>;
/**
* State used in rendering SwatchPickerRow
*/
export type SwatchPickerRowState = ComponentState<SwatchPickerRowSlots>;
export type SwatchPickerRowState = ComponentState<SwatchPickerRowSlots> & Pick<SwatchPickerProps, 'spacing'>;
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import * as React from 'react';
import { getIntrinsicElementProps, slot } from '@fluentui/react-utilities';
import type { SwatchPickerRowProps, SwatchPickerRowState } from './SwatchPickerRow.types';
import { swatchPickerCSSVars } from './useSwatchPickerRowStyles.styles';
import { useSwatchPickerContextValue_unstable } from '../../contexts/swatchPicker';
import { spacingMap } from '../SwatchPicker/useSwatchPicker';

const { rowGap } = swatchPickerCSSVars;

/**
* Create the state required to render SwatchPickerRow.
Expand All @@ -32,12 +28,9 @@ export const useSwatchPickerRow_unstable = (
ref,
role: 'row',
...rest,
style: {
[rowGap]: spacingMap[spacing ?? 'medium'],
...style,
},
}),
{ elementType: 'div' },
),
spacing,
};
};
Original file line number Diff line number Diff line change
@@ -1,32 +1,37 @@
import { makeResetStyles, mergeClasses } from '@griffel/react';
import { makeResetStyles, mergeClasses, makeStyles } from '@griffel/react';
import type { SlotClassNames } from '@fluentui/react-utilities';
import type { SwatchPickerRowSlots, SwatchPickerRowState } from './SwatchPickerRow.types';

export const swatchPickerCSSVars = {
rowGap: `--fui-SwatchPicker--rowGap`,
};

const { rowGap } = swatchPickerCSSVars;

export const swatchPickerRowClassNames: SlotClassNames<SwatchPickerRowSlots> = {
root: 'fui-SwatchPickerRow',
};

/**
* Styles for the root slot
*/
const useStyles = makeResetStyles({
const useResetStyles = makeResetStyles({
display: 'flex',
flexDirection: 'row',
columnGap: `var(${rowGap})`,
});

const useStyles = makeStyles({
spacingSmall: {
columnGap: '2px',
},
spacingMedium: {
columnGap: '4px',
},
});

/**
* Apply styling to the SwatchPickerRow slots based on the state
*/
export const useSwatchPickerRowStyles_unstable = (state: SwatchPickerRowState): SwatchPickerRowState => {
const resetStyles = useResetStyles();
const styles = useStyles();
state.root.className = mergeClasses(swatchPickerRowClassNames.root, styles, state.root.className);
const spacingStyle = state.spacing === 'small' ? styles.spacingSmall : styles.spacingMedium;

state.root.className = mergeClasses(swatchPickerRowClassNames.root, resetStyles, spacingStyle, state.root.className);

return state;
};
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export type SwatchPickerContextValue = Pick<SwatchPickerProps, 'size' | 'shape'
isGrid: boolean;

/**
* @internal
* Callback used by ColorSwatch to request a change on it's selected state
* Should be used to select ColorSwatch
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ export {
useSwatchPickerStyles_unstable,
useSwatchPicker_unstable,
swatchPickerClassNames,
swatchPickerCSSVars,
} from './SwatchPicker';
export type {
SwatchPickerProps,
Expand Down