Skip to content

Commit

Permalink
MenuRenderer, OverflowMenu: add small size (#1675)
Browse files Browse the repository at this point in the history
Co-authored-by: Michael Taranto <[email protected]>
Co-authored-by: Michael Taranto <[email protected]>
  • Loading branch information
3 people authored Dec 23, 2024
1 parent 0ce0f19 commit 8029534
Show file tree
Hide file tree
Showing 24 changed files with 929 additions and 144 deletions.
19 changes: 19 additions & 0 deletions .changeset/wicked-dancers-end.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
'braid-design-system': minor
---

---
updated:
- MenuRenderer
- OverflowMenu
---

**MenuRenderer, OverflowMenu:** Add `small` size.

Introduce a new `small` size for `MenuRenderer` and `OverflowMenu`.
This is available via the `size` prop, which supports the existing `standard` (default) and `small`.

**EXAMPLE USAGE:**
```jsx
<MenuRenderer size="small" ... />
```
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { DefaultTextPropsProvider } from '../private/defaultTextProps';
import { TextContext } from '../Text/TextContext';
import HeadingContext from '../Heading/HeadingContext';
import * as styles from './Badge.css';
import { useDefaultBadgeProps } from './defaultBadgeProps';

type ValueOrArray<T> = T | T[];

Expand Down Expand Up @@ -61,7 +62,7 @@ export const Badge = forwardRef<HTMLSpanElement, BadgeProps>(
{
tone = 'info',
weight = 'regular',
bleedY = false,
bleedY: bleedYProp,
title,
children,
id,
Expand All @@ -88,6 +89,8 @@ export const Badge = forwardRef<HTMLSpanElement, BadgeProps>(
const headingContext = useContext(HeadingContext);
const isInline = Boolean(textContext || headingContext);

const { bleedY } = useDefaultBadgeProps({ bleedY: bleedYProp });

assert(
!isInline || (isInline && bleedY === false),
'A `Badge` cannot use `bleedY` when rendered inside a `Text` or `Heading` component.',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { createContext, useContext, useMemo, type ReactNode } from 'react';
import type { BadgeProps } from './Badge';

interface DefaultBadgeProps {
bleedY: BadgeProps['bleedY'];
}

const DefaultBadgePropsContext = createContext<DefaultBadgeProps>({
bleedY: undefined,
});

interface DefaultBadgePropsProviderProps extends DefaultBadgeProps {
children: ReactNode;
}

export const DefaultBadgePropsProvider = ({
bleedY,
children,
}: DefaultBadgePropsProviderProps) => {
const defaultBadgeProps = useMemo(
() => ({
bleedY,
}),
[bleedY],
);

return (
<DefaultBadgePropsContext.Provider value={defaultBadgeProps}>
{children}
</DefaultBadgePropsContext.Provider>
);
};

export const useDefaultBadgeProps = ({
bleedY: bleedYProp,
}: DefaultBadgeProps) => {
const { bleedY } = useContext(DefaultBadgePropsContext);

return {
bleedY: bleedYProp ?? bleedY ?? false,
};
};
Loading

0 comments on commit 8029534

Please sign in to comment.