Skip to content

Commit

Permalink
Use export * in utility indexes too
Browse files Browse the repository at this point in the history
  • Loading branch information
BPScott committed Jan 20, 2020
1 parent 41105a5 commit a290073
Show file tree
Hide file tree
Showing 18 changed files with 46 additions and 60 deletions.
1 change: 1 addition & 0 deletions UNRELEASED.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@

- Converted `/tests/build.test.js` to TypeScript ([#2617](https://github.com/Shopify/polaris-react/pull/2617))
- Use `export *` to rexport component content in component indexs and subcomponent listings ([#2625](https://github.com/Shopify/polaris-react/pull/2625))
- Use `export *` to rexport utility content ([#2636](https://github.com/Shopify/polaris-react/pull/2636))

### Deprecations
15 changes: 8 additions & 7 deletions src/components/ThemeProvider/ThemeProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,20 @@ import {
DefaultThemeColors,
DefaultColorScheme,
Tokens,
ColorScheme,
} from '../../utilities/theme';
import {useFeatures} from '../../utilities/features';

type OriginalColorScheme = Required<ThemeConfig['colorScheme']>;
type Inverse = 'inverse';
type InversableColorScheme = OriginalColorScheme | Inverse;

// TS 3.5+ includes the built-in Omit type which does the same thing. But if we
// use that then we break consumers on older versions of TS. Consider removing
// this when we drop support for consumers using TS <3.5 (in v5?)
type Discard<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;

interface ThemeProviderThemeConfig extends Discard<ThemeConfig, 'colorScheme'> {
colorScheme?: ColorScheme | Inverse;
colorScheme?: InversableColorScheme;
}

interface ThemeProviderProps {
Expand Down Expand Up @@ -101,14 +102,14 @@ export function ThemeProvider({
}

function isInverseColorScheme(
colorScheme?: ColorScheme | Inverse,
colorScheme?: InversableColorScheme,
): colorScheme is Inverse {
return colorScheme === 'inverse';
}

function getColorScheme(
colorScheme: ColorScheme | Inverse | undefined,
parentColorScheme: ColorScheme | undefined,
colorScheme: InversableColorScheme | undefined,
parentColorScheme: OriginalColorScheme | undefined,
) {
if (colorScheme == null) {
return parentColorScheme || DefaultColorScheme;
Expand All @@ -123,8 +124,8 @@ function getColorScheme(

function shouldInheritParentColors(
isParentThemeProvider: boolean,
colorScheme: ColorScheme | Inverse | undefined,
parentColorScheme: ColorScheme | undefined,
colorScheme: InversableColorScheme | undefined,
parentColorScheme: OriginalColorScheme | undefined,
) {
if (isParentThemeProvider) {
return false;
Expand Down
4 changes: 2 additions & 2 deletions src/utilities/app-bridge/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export {AppBridgeContext} from './context';
export * from './context';

export {useAppBridge} from './hooks';
export * from './hooks';

export {createAppBridge, AppBridgeOptions} from './app-bridge';
6 changes: 3 additions & 3 deletions src/utilities/features/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export {FeaturesContext} from './context';
export * from './context';

export {Features} from './types';
export * from './types';

export {useFeatures} from './hooks';
export * from './hooks';
1 change: 1 addition & 0 deletions src/utilities/frame/context.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
import {ToastPropsWithID, ToastID, ContextualSaveBarProps} from './types';

// This is internal, but TS throws a build-time error if we don't export it
export interface FrameContextType {
showToast(toast: ToastPropsWithID): void;
hideToast(toast: ToastID): void;
Expand Down
11 changes: 3 additions & 8 deletions src/utilities/frame/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
export {useFrame} from './hooks';
export * from './hooks';

export {FrameContext} from './context';
export * from './context';

export {
ContextualSaveBarProps,
ToastProps,
ToastID,
ToastPropsWithID,
} from './types';
export * from './types';
6 changes: 3 additions & 3 deletions src/utilities/i18n/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export {I18nContext} from './context';
export * from './context';

export {useI18n} from './hooks';
export * from './hooks';

export {I18n} from './I18n';
export * from './I18n';
6 changes: 3 additions & 3 deletions src/utilities/link/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export {LinkLikeComponentProps, LinkLikeComponent} from './types';
export * from './types';

export {useLink} from './hooks';
export * from './hooks';

export {LinkContext} from './context';
export * from './context';
1 change: 1 addition & 0 deletions src/utilities/media-query/context.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';

// This is internal, but TS throws a build-time error if we don't export it
export interface MediaQueryContextType {
isNavigationCollapsed: boolean;
}
Expand Down
4 changes: 2 additions & 2 deletions src/utilities/media-query/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export {MediaQueryContext} from './context';
export {useMediaQuery} from './hooks';
export * from './context';
export * from './hooks';
1 change: 1 addition & 0 deletions src/utilities/resource-list/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import React from 'react';
import {CheckboxHandles} from '../../types';
import {ResourceListSelectedItems, CheckableButtonKey} from './types';

// This is internal, but TS throws a build-time error if we don't export it
export interface ResourceListContextType {
registerCheckableButtons?(
key: CheckableButtonKey,
Expand Down
9 changes: 2 additions & 7 deletions src/utilities/resource-list/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
export {ResourceListContext} from './context';
export * from './context';

export {
ResourceListSelectedItems,
SELECT_ALL_ITEMS,
CheckableButtons,
CheckableButtonKey,
} from './types';
export * from './types';
9 changes: 3 additions & 6 deletions src/utilities/scroll-lock-manager/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
export {ScrollLockManagerContext} from './context';
export * from './context';

export {useScrollLockManager} from './hooks';
export * from './hooks';

export {
ScrollLockManager,
SCROLL_LOCKING_ATTRIBUTE,
} from './scroll-lock-manager';
export * from './scroll-lock-manager';
4 changes: 1 addition & 3 deletions src/utilities/scroll-lock-manager/scroll-lock-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ import {isServer} from '../target';

export const SCROLL_LOCKING_ATTRIBUTE = 'data-lock-scrolling';

export const SCROLL_LOCKING_WRAPPER_ATTRIBUTE = 'data-lock-scrolling-wrapper';

export const SCROLL_LOCKING_CUSTOM_PROPERTY = '--scroll-lock-body-padding';
const SCROLL_LOCKING_WRAPPER_ATTRIBUTE = 'data-lock-scrolling-wrapper';

let scrollPosition = 0;

Expand Down
6 changes: 3 additions & 3 deletions src/utilities/sticky-manager/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export {StickyManagerContext} from './context';
export * from './context';

export {useStickyManager} from './hooks';
export * from './hooks';

export {StickyManager} from './sticky-manager';
export * from './sticky-manager';
2 changes: 1 addition & 1 deletion src/utilities/sticky-manager/sticky-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import tokens from '@shopify/polaris-tokens';
import {dataPolarisTopBar, scrollable} from '../../components/shared';
import {stackedContent} from '../breakpoints';

export interface StickyItem {
interface StickyItem {
/** Node of the sticky element */
stickyNode: HTMLElement;
/** Placeholder element */
Expand Down
14 changes: 5 additions & 9 deletions src/utilities/theme/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
export {ThemeContext} from './context';
export * from './context';

export {useTheme} from './hooks';
export * from './hooks';

export {Theme, ThemeConfig, CustomPropertiesLike, ColorScheme} from './types';
export {ThemeConfig} from './types';

export {
DefaultThemeColors,
DefaultColorScheme,
roleVariants,
} from './role-variants';
export * from './role-variants';

export {
buildCustomProperties,
Expand All @@ -17,4 +13,4 @@ export {
toCssCustomPropertySyntax,
} from './utils';

export {Tokens} from './tokens';
export * from './tokens';
6 changes: 3 additions & 3 deletions src/utilities/unique-id/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export {UniqueIdFactoryContext} from './context';
export * from './context';

export {useUniqueId} from './hooks';
export * from './hooks';

export {UniqueIdFactory, globalIdGeneratorFactory} from './unique-id-factory';
export * from './unique-id-factory';

0 comments on commit a290073

Please sign in to comment.