Skip to content

Commit 087208d

Browse files
authored
feat: add the ability to un-mount global styles (#253)
* minimum changes * clean more issues * fix more issues * v2.0.0-0 * remove size limit
1 parent 8f81ef4 commit 087208d

File tree

13 files changed

+34
-28
lines changed

13 files changed

+34
-28
lines changed

.github/workflows/size.yml

-12
This file was deleted.

package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "1.8.11",
2+
"version": "2.0.0-0",
33
"license": "MIT",
44
"main": "dist/index.js",
55
"typings": "dist/index.d.ts",
@@ -22,6 +22,7 @@
2222
"analyze": "size-limit --why",
2323
"storybook": "start-storybook -p 6006",
2424
"build-storybook": "build-storybook",
25+
"typecheck": "tsc --noEmit",
2526
"chromatic": "npx chromatic --project-token 1yugawkzsgd"
2627
},
2728
"peerDependencies": {
@@ -87,7 +88,7 @@
8788
"ts-dedent": "^2.2.0",
8889
"tsdx": "^0.14.1",
8990
"tslib": "^2.0.3",
90-
"typescript": "^4.9.5"
91+
"typescript": "5.4.5"
9192
},
9293
"resolutions": {
9394
"react": "^18",

src/button/styles.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export const buttonCSS = css`
1919
}
2020
&[disabled] {
2121
cursor: default;
22-
opacity: ${theme.opacity.disabled};
22+
opacity: var(--ac-opacity-disabled);
2323
}
2424
&[data-size='default'][data-childless='false'] {
2525
padding: var(--ac-global-dimension-static-size-100)

src/listbox/ListBoxBase.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ function ListBoxBase<T>(
144144
style={props.style}
145145
{...mergeProps(listBoxProps, domProps)}
146146
ref={ref}
147-
focusedKey={state.selectionManager.focusedKey}
147+
focusedKey={state.selectionManager.focusedKey || undefined}
148148
sizeToFit="height"
149149
scrollDirection="vertical"
150150
className="ac-menu"

src/menu/MenuTrigger.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ function MenuTrigger(props: MenuTriggerProps, ref: DOMRef<HTMLElement>) {
125125
isOpen={state.isOpen}
126126
style={positionProps.style}
127127
ref={menuPopoverRef}
128-
placement={placement}
128+
placement={placement || undefined}
129129
onClose={state.close}
130130
shouldCloseOnBlur
131131
>

src/picker/Picker.tsx

+3-2
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,13 @@ function Picker<T extends object>(
7777
unwrappedTriggerRef
7878
);
7979

80+
const propsPlacement = `${direction} ${align}` as Placement;
8081
const { overlayProps, placement, updatePosition } = useOverlayPosition({
8182
targetRef: unwrappedTriggerRef,
8283
overlayRef: unwrappedDropdownRef,
8384
// @ts-ignore refs are not playing nicely with hooks
8485
scrollRef: listboxRef,
85-
placement: `${direction} ${align}` as Placement,
86+
placement: propsPlacement,
8687
shouldFlip: shouldFlip,
8788
isOpen: state.isOpen,
8889
onClose: state.close,
@@ -162,7 +163,7 @@ function Picker<T extends object>(
162163
className={classNames('ac-dropdown', props.className)}
163164
// @ts-ignore
164165
ref={dropdownRef}
165-
placement={placement}
166+
placement={placement || 'center'}
166167
hideArrow
167168
shouldCloseOnBlur
168169
onClose={state.close}

src/popover/PopoverTrigger.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export function PopoverTrigger(props: PopoverTriggerProps) {
5858
isOpen={state.isOpen}
5959
ref={overlayRef}
6060
onClose={state.close}
61-
placement={placement}
61+
placement={placement || 'bottom'}
6262
{...popoverProps}
6363
>
6464
{typeof content === 'function' ? content(state.close) : content}

src/progress/ProgressBar.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ function ProgressBar(props: ACProgressBarProps, ref: DOMRef<HTMLDivElement>) {
1212
return (
1313
<ProgressBarBase
1414
{...otherProps}
15-
ref={ref}
15+
ref={ref as any}
1616
barProps={progressBarProps}
1717
labelProps={labelProps}
1818
barClassName={classNames({

src/provider/GlobalStyles.tsx

+6-1
Original file line numberDiff line numberDiff line change
@@ -1016,6 +1016,10 @@ export const derivedCSS = (theme: ProviderTheme) => css`
10161016
--ac-alias-single-line-width: var(--ac-global-dimension-size-2400);
10171017
}
10181018
`;
1019+
1020+
const opacitiesCSS = css`
1021+
--ac-opacity-disabled: 0.6;
1022+
`;
10191023
export function GlobalStyles() {
10201024
let { theme } = useProvider();
10211025
theme = theme || 'dark';
@@ -1027,7 +1031,8 @@ export function GlobalStyles() {
10271031
staticCSS,
10281032
themeCSS,
10291033
derivedCSS(theme),
1030-
mediumRootCSS
1034+
mediumRootCSS,
1035+
opacitiesCSS
10311036
)}
10321037
/>
10331038
);

src/provider/Provider.tsx

+7-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@ const Context = React.createContext<ProviderContext | null>(null);
77

88
export function Provider(props: ProviderProps) {
99
const prevContext = useContext(Context);
10-
const { children, theme: propsTheme, ...context } = props;
10+
const {
11+
children,
12+
theme: propsTheme,
13+
mountGlobalStyles = true,
14+
...context
15+
} = props;
1116
let theme: ProviderTheme = propsTheme || 'dark';
1217
const isRootProvider = !prevContext;
1318
// If there is a theme higher up in the tree, use that theme
@@ -21,7 +26,7 @@ export function Provider(props: ProviderProps) {
2126
);
2227
return (
2328
<Context.Provider value={{ ...context, theme }}>
24-
{isRootProvider ? <GlobalStyles /> : null}
29+
{isRootProvider && mountGlobalStyles ? <GlobalStyles /> : null}
2530
<div className={`ac-theme ac-theme--${theme}`}>{content}</div>
2631
</Context.Provider>
2732
);

src/tooltip/TooltipTrigger.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export function TooltipTrigger(props: TooltipTriggerProps) {
5959
);
6060

6161
const { overlayProps, arrowProps, placement } = useOverlayPosition({
62-
placement: props.placement || 'top',
62+
placement: props.placement,
6363
targetRef: tooltipTriggerRef,
6464
overlayRef,
6565
offset,
@@ -73,7 +73,7 @@ export function TooltipTrigger(props: TooltipTriggerProps) {
7373
<TooltipContext.Provider
7474
value={{
7575
state,
76-
placement,
76+
placement: placement || 'top',
7777
ref: overlayRef,
7878
style: overlayProps.style,
7979
arrowProps,

src/types/collection.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export interface Node<T> {
7676
/** An accessibility label for this node. */
7777
'aria-label'?: string;
7878
/** The index of this node within its parent. */
79-
index?: number;
79+
index: number;
8080
/** A function that should be called to wrap the rendered node. */
8181
wrapper?: (element: ReactElement) => ReactElement;
8282
/** The key of the parent node. */

src/types/provider.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ interface ContextProps {
1616
export interface ProviderProps extends ContextProps {
1717
/** The content of the Provider. */
1818
children: ReactNode;
19+
/**
20+
* Whether or not to mount the global styles. This should only be set to false if
21+
* you are wanting to manually set the global design tokens.
22+
* @default true
23+
*/
24+
mountGlobalStyles?: boolean;
1925
}
2026

21-
export type ProviderContext = ContextProps
27+
export type ProviderContext = ContextProps;

0 commit comments

Comments
 (0)