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

Use export * in utility indexes too #2636

Merged
merged 1 commit into from
Jan 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are you sure we can remove this?

Copy link
Member Author

@BPScott BPScott Jan 22, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked for usages and there were none outside the current file, I then removed the export and it complained that it was never used inside this file either

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';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not export * here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a bunch of other types in that file that are used within this folder, but not externally. As most of this is going to be extracted into polaris-tokens pretty soon it didn't seem worth the refactoring to split this into a types and private-types file.


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';