Skip to content

Commit

Permalink
[Joy] Use orientation prop for consistency (#33786)
Browse files Browse the repository at this point in the history
  • Loading branch information
siriwatknp authored Aug 4, 2022
1 parent 58b5d72 commit 17f04ee
Show file tree
Hide file tree
Showing 54 changed files with 222 additions and 194 deletions.
2 changes: 1 addition & 1 deletion docs/data/joy/components/aspect-ratio/CarouselRatio.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export default function CarouselRatio() {
>
{data.map((item) => (
<Card
row
orientation="horizontal"
key={item.title}
variant="outlined"
sx={{
Expand Down
2 changes: 1 addition & 1 deletion docs/data/joy/components/aspect-ratio/CarouselRatio.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export default function CarouselRatio() {
>
{data.map((item) => (
<Card
row
orientation="horizontal"
key={item.title}
variant="outlined"
sx={{
Expand Down
2 changes: 1 addition & 1 deletion docs/data/joy/components/card/InteractiveCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default function InteractiveCard() {
return (
<Card
variant="outlined"
row
orientation="horizontal"
sx={{
minWidth: '320px',
gap: 2,
Expand Down
2 changes: 1 addition & 1 deletion docs/data/joy/components/card/InteractiveCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default function InteractiveCard() {
return (
<Card
variant="outlined"
row
orientation="horizontal"
sx={{
minWidth: '320px',
gap: 2,
Expand Down
2 changes: 1 addition & 1 deletion docs/data/joy/components/card/RowCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import Typography from '@mui/joy/Typography';
export default function InteractiveCard() {
return (
<Card
row
orientation="horizontal"
variant="outlined"
sx={{
minWidth: '260px',
Expand Down
2 changes: 1 addition & 1 deletion docs/data/joy/components/card/RowCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import Typography from '@mui/joy/Typography';
export default function InteractiveCard() {
return (
<Card
row
orientation="horizontal"
variant="outlined"
sx={{
minWidth: '260px',
Expand Down
2 changes: 1 addition & 1 deletion docs/data/joy/components/checkbox/ExampleButtonCheckbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default function ExampleButtonCheckbox() {
variant="soft"
aria-label="Screens"
role="group"
row
orientation="horizontal"
sx={{
flexGrow: 0,
'--List-gap': '8px',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default function ExampleChoiceChipCheckbox() {
</Typography>
<Box role="group" aria-labelledby="rank">
<List
row
orientation="horizontal"
wrap
sx={{
'--List-gap': '8px',
Expand Down
2 changes: 1 addition & 1 deletion docs/data/joy/components/checkbox/IconlessCheckbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default function IconlessCheckbox() {
</Typography>
<Box role="group" aria-labelledby="topping">
<List
row
orientation="horizontal"
wrap
sx={{
'--List-gap': '8px',
Expand Down
2 changes: 1 addition & 1 deletion docs/data/joy/components/chip/RadioChip.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default function RadioChip() {
<RadioGroup
name="best-movie"
aria-labelledby="best-movie"
row
orientation="horizontal"
sx={{ flexWrap: 'wrap', gap: 1 }}
>
{[
Expand Down
2 changes: 1 addition & 1 deletion docs/data/joy/components/chip/RadioChip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default function RadioChip() {
<RadioGroup
name="best-movie"
aria-labelledby="best-movie"
row
orientation="horizontal"
sx={{ flexWrap: 'wrap', gap: 1 }}
>
{[
Expand Down
2 changes: 1 addition & 1 deletion docs/data/joy/components/list/ExampleNavigationMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ export default function ExampleNavigationMenu() {
<Box sx={{ minHeight: 190 }}>
<List
role="menubar"
row
orientation="horizontal"
sx={{
'--List-radius': '8px',
'--List-padding': '4px',
Expand Down
2 changes: 1 addition & 1 deletion docs/data/joy/components/list/HorizontalDividedList.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import ListItemDecorator from '@mui/joy/ListItemDecorator';
export default function HorizontalDividedList() {
return (
<List
row
orientation="horizontal"
variant="outlined"
sx={{
borderRadius: 'sm',
Expand Down
2 changes: 1 addition & 1 deletion docs/data/joy/components/list/HorizontalList.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Person from '@mui/icons-material/Person';
export default function HorizontalList() {
return (
<Box component="nav" aria-label="My site" sx={{ flexGrow: 1 }}>
<List role="menubar" row>
<List role="menubar" orientation="horizontal">
<ListItem role="none">
<ListItemButton
role="menuitem"
Expand Down
2 changes: 1 addition & 1 deletion docs/data/joy/components/menu/MenuToolbarExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export default function MenuToolbarExample() {

return (
<List
row
orientation="horizontal"
aria-label="Example application menu bar"
role="menubar"
data-joy-color-scheme="dark"
Expand Down
2 changes: 1 addition & 1 deletion docs/data/joy/components/radio/ExampleAlignmentButtons.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default function RadioButtonsGroup() {
const [alignment, setAlignment] = React.useState('left');
return (
<RadioGroup
row
orientation="horizontal"
aria-label="Alignment"
name="alignment"
variant="outlined"
Expand Down
2 changes: 1 addition & 1 deletion docs/data/joy/components/radio/ExamplePaymentChannels.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export default function ExamplePaymentChannels() {
>
<List
variant="outlined"
row={row}
orientation={row ? 'horizontal' : 'vertical'}
sx={{
borderRadius: 'sm',
boxShadow: 'sm',
Expand Down
2 changes: 1 addition & 1 deletion docs/data/joy/components/radio/OverlayRadio.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default function OverlayRadio() {
name="member"
aria-labelledby="member"
defaultValue="person1"
row
orientation="horizontal"
sx={{ gap: 2 }}
>
{[1, 2, 3].map((num) => (
Expand Down
15 changes: 9 additions & 6 deletions docs/data/joy/components/radio/RadioUsage.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,19 @@ export default function RadioUsage() {
defaultValue: 'md',
},
{
propName: 'row',
knob: 'switch',
defaultValue: false,
propName: 'orientation',
knob: 'radio',
options: ['vertical', 'horizontal'],
defaultValue: 'vertical',
codeBlockDisplay: false,
},
]}
getCodeBlock={(code, props) => `<RadioGroup${props.row ? ` row` : ''}>
getCodeBlock={(code, props) => `<RadioGroup${
props.row ? ` orientation="horizontal"` : ''
}>
${prependLinesSpace(code, 2)}
</RadioGroup>`}
renderDemo={({ row, ...props }) => (
renderDemo={({ orientation, ...props }) => (
<div>
<FormLabel
id="radio-button-usage-label"
Expand All @@ -54,7 +57,7 @@ ${prependLinesSpace(code, 2)}
Pizza crust
</FormLabel>
<RadioGroup
row={row}
orientation={orientation}
defaultValue="1"
name="radio-button-usage"
aria-labelledby="radio-button-usage-label"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ export default function EmailContent() {
/>
</AspectRatio>
</Card>
<Card variant="outlined" row>
<Card variant="outlined" orientation="horizontal">
<CardOverflow>
<AspectRatio ratio="1" sx={{ minWidth: 80 }}>
<Box
Expand Down
4 changes: 2 additions & 2 deletions docs/src/modules/components/JoyUsageDemo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ export default function JoyUsageDemo<T extends { [k: string]: any } = {}>({
{propName}
</Typography>
<RadioGroup
row
orientation="horizontal"
name={labelId}
aria-labelledby={labelId}
value={resolvedValue}
Expand Down Expand Up @@ -343,7 +343,7 @@ export default function JoyUsageDemo<T extends { [k: string]: any } = {}>({
Color
</Typography>
<RadioGroup
row
orientation="horizontal"
name={`${componentName}-color`}
aria-labelledby={`${componentName}-color`}
value={resolvedValue || ''}
Expand Down
22 changes: 11 additions & 11 deletions packages/mui-joy/src/Card/Card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ import styled from '../styles/styled';
import { getCardUtilityClass } from './cardClasses';
import { CardProps, CardTypeMap } from './CardProps';
import { resolveSxValue } from '../styles/styleUtils';
import { CardRowContext } from './CardContext';
import { CardOrientationContext } from './CardContext';

const useUtilityClasses = (ownerState: CardProps) => {
const { size, variant, color, row } = ownerState;
const { size, variant, color, orientation } = ownerState;

const slots = {
root: [
'root',
orientation,
variant && `variant${capitalize(variant)}`,
color && `color${capitalize(color)}`,
size && `size${capitalize(size)}`,
row && 'row',
],
};

Expand Down Expand Up @@ -74,7 +74,7 @@ const CardRoot = styled('div', {
transition: 'box-shadow 300ms cubic-bezier(0.4, 0, 0.2, 1) 0ms',
position: 'relative',
display: 'flex',
flexDirection: ownerState.row ? 'row' : 'column',
flexDirection: ownerState.orientation === 'horizontal' ? 'row' : 'column',
},
theme.variants[ownerState.variant!]?.[ownerState.color!],
]);
Expand All @@ -92,23 +92,23 @@ const Card = React.forwardRef(function Card(inProps, ref) {
size = 'md',
variant = 'plain',
children,
row = false,
orientation = 'vertical',
...other
} = props;

const ownerState = {
...props,
color,
component,
row,
orientation,
size,
variant,
};

const classes = useUtilityClasses(ownerState);

return (
<CardRowContext.Provider value={row}>
<CardOrientationContext.Provider value={orientation}>
<CardRoot
as={component}
ownerState={ownerState}
Expand All @@ -129,7 +129,7 @@ const Card = React.forwardRef(function Card(inProps, ref) {
return child;
})}
</CardRoot>
</CardRowContext.Provider>
</CardOrientationContext.Provider>
);
}) as OverridableComponent<CardTypeMap>;

Expand Down Expand Up @@ -161,10 +161,10 @@ Card.propTypes /* remove-proptypes */ = {
*/
component: PropTypes.elementType,
/**
* If `true`, flex direction is set to 'row'.
* @default false
* The flow direction of the content.
* @default 'vertical'
*/
row: PropTypes.bool,
orientation: PropTypes.oneOf(['horizontal', 'vertical']),
/**
* The size of the component.
* It accepts theme values between 'xs' and 'xl'.
Expand Down
2 changes: 1 addition & 1 deletion packages/mui-joy/src/Card/CardContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ import * as React from 'react';

// internal logic
// eslint-disable-next-line import/prefer-default-export
export const CardRowContext = React.createContext<boolean>(false);
export const CardOrientationContext = React.createContext<'vertical' | 'horizontal'>('vertical');
6 changes: 3 additions & 3 deletions packages/mui-joy/src/Card/CardProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ export interface CardTypeMap<P = {}, D extends React.ElementType = 'div'> {
*/
color?: OverridableStringUnion<ColorPaletteProp, CardPropsColorOverrides>;
/**
* If `true`, flex direction is set to 'row'.
* @default false
* The flow direction of the content.
* @default 'vertical'
*/
row?: boolean;
orientation?: 'vertical' | 'horizontal';
/**
* The size of the component.
* It accepts theme values between 'xs' and 'xl'.
Expand Down
9 changes: 6 additions & 3 deletions packages/mui-joy/src/Card/cardClasses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ export interface CardClasses {
sizeMd: string;
/** Styles applied to the root element if `size="lg"`. */
sizeLg: string;
/** Styles applied to the root element if `row={true}`. */
row: string;
/** Styles applied to the root element, if `orientation="vertical"`. */
vertical: string;
/** Styles applied to the root element, if `orientation="horizontal"`. */
horizontal: string;
}

export type CardClassKey = keyof CardClasses;
Expand All @@ -54,7 +56,8 @@ const cardClasses: CardClasses = generateUtilityClasses('JoyCard', [
'sizeSm',
'sizeMd',
'sizeLg',
'row',
'vertical',
'horizontal',
]);

export default cardClasses;
10 changes: 5 additions & 5 deletions packages/mui-joy/src/CardOverflow/CardOverflow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { useThemeProps } from '../styles';
import styled from '../styles/styled';
import { getCardOverflowUtilityClass } from './cardOverflowClasses';
import { CardOverflowProps, CardOverflowTypeMap } from './CardOverflowProps';
import { CardRowContext } from '../Card/CardContext';
import { CardOrientationContext } from '../Card/CardContext';

const useUtilityClasses = (ownerState: CardOverflowProps) => {
const { variant, color } = ownerState;
Expand All @@ -29,14 +29,14 @@ const CardOverflowRoot = styled('div', {
overridesResolver: (props, styles) => styles.root,
})<{
ownerState: CardOverflowProps & {
row: boolean;
orientation: 'horizontal' | 'vertical';
'data-first-child'?: string;
'data-last-child'?: string;
};
}>(({ theme, ownerState }) => {
const childRadius = 'calc(var(--CardOverflow-radius) - var(--variant-borderWidth))';
return [
ownerState.row
ownerState.orientation === 'horizontal'
? {
'--AspectRatio-margin': 'calc(-1 * var(--Card-padding)) 0px',
marginTop: 'var(--CardOverflow-offset)',
Expand Down Expand Up @@ -89,7 +89,7 @@ const CardOverflow = React.forwardRef(function CardOverflow(inProps, ref) {
name: 'JoyCardOverflow',
});

const row = React.useContext(CardRowContext);
const orientation = React.useContext(CardOrientationContext);

const {
className,
Expand All @@ -105,7 +105,7 @@ const CardOverflow = React.forwardRef(function CardOverflow(inProps, ref) {
component,
color,
variant,
row,
orientation,
};

const classes = useUtilityClasses(ownerState);
Expand Down
Loading

0 comments on commit 17f04ee

Please sign in to comment.