Skip to content
Closed
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
8 changes: 8 additions & 0 deletions .changeset/bright-dingos-arrive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
'@alfalab/core-components-select': minor
'@alfalab/core-components': minor
---

##### Select:

- Добавлена поддержка `environment` через `CoreConfigContext`
7 changes: 7 additions & 0 deletions .changeset/thick-colts-wave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@alfalab/core-components-config': minor
---

##### CoreConfigContext:

- Добавлена поддержка `environment` для переопредения `window` в случае с `ShadowRoot`
1 change: 1 addition & 0 deletions packages/config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"main": "index.js",
"module": "./esm/index.js",
"dependencies": {
"@alfalab/core-components-shared": "^1.1.1",
"tslib": "^2.4.0"
},
"peerDependencies": {
Expand Down
14 changes: 14 additions & 0 deletions packages/config/src/CoreConfigContext.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,27 @@
import { createContext, useContext } from 'react';

import { isClient } from '@alfalab/core-components-shared';

/**
* copy-paste from https://github.com/downshift-js/downshift/blob/a583281aefaaf33cb1a6c393967a060c61911e43/typings/index.d.ts#L83
*/
export interface Environment {
addEventListener: typeof window.addEventListener;
removeEventListener: typeof window.removeEventListener;
document: Document;
Node: typeof window.Node;
}

export type CoreConfigContextValue = {
breakpoint: number;
client: 'desktop' | 'mobile';
environment?: Environment;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Может хоть js doc какой то добавить тут? По названию понять для чего вообще эта штука нужна не возможно. Ну и в доку бы по селекту добавить что-то типа "бла-бла, в шадоу доме используйте то-то то-то"?

Copy link
Copy Markdown
Collaborator Author

@hextion hextion Dec 4, 2025

Choose a reason for hiding this comment

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

example

const env: Environment | undefined = (() => {
  const shadowRoot = document.querySelector('')?.shadowRoot;
  
  if (!shadowRoot) {
    return undefined;
  }
  
  
  return {
    addEventListener: shadowRoot.addEventListener.bind(shadowRoot),
    removeEventListener: shadowRoot.removeEventListener.bind(shadowRoot),
    document,
    Node,
  }
})();

};

export const CoreConfigContext = createContext<CoreConfigContextValue>({
breakpoint: 1024,
client: 'desktop',
environment: isClient() ? window : undefined,
});

export const useCoreConfig = (overrides: Partial<CoreConfigContextValue> = {}) => {
Expand Down
7 changes: 5 additions & 2 deletions packages/config/tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
"outDir": "ts-dist",
"paths": {
"@alfalab/core-components-config": ["./src"],
"@alfalab/core-components-config/*": ["./src/*"]
"@alfalab/core-components-config/*": ["./src/*"],
"@alfalab/core-components-shared": ["../shared/src"],
"@alfalab/core-components-shared/*": ["../shared/src/*"]
}
}
},
"references": [{ "path": "../shared/tsconfig.build.json" }]
}
3 changes: 3 additions & 0 deletions packages/config/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@
"@alfalab/core-components-config/*": ["./src/*"],
"@alfalab/core-components-screenshot-utils": ["../screenshot-utils/src"],
"@alfalab/core-components-screenshot-utils/*": ["../screenshot-utils/src/*"],
"@alfalab/core-components-shared": ["../shared/src"],
"@alfalab/core-components-shared/*": ["../shared/src/*"],
"@alfalab/core-components-test-utils": ["../test-utils/src"],
"@alfalab/core-components-test-utils/*": ["../test-utils/src/*"]
}
},
"references": [
{ "path": "../screenshot-utils/tsconfig.build.json" },
{ "path": "../shared/tsconfig.build.json" },
{ "path": "../test-utils/tsconfig.build.json" }
]
}
1 change: 1 addition & 0 deletions packages/select/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"tslib": "^2.4.0"
},
"peerDependencies": {
"@alfalab/core-components-config": "^1.0.0",
"react": "^16.9.0 || ^17.0.1 || ^18.0.0",
"react-dom": "^16.9.0 || ^17.0.1 || ^18.0.0"
},
Expand Down
8 changes: 5 additions & 3 deletions packages/select/src/components/base-select/Component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ import {
type UseMultipleSelectionState,
} from 'downshift';

import { fnUtils, getDataTestId, isClient } from '@alfalab/core-components-shared';
import { useCoreConfig } from '@alfalab/core-components-config';
import { fnUtils, getDataTestId } from '@alfalab/core-components-shared';
import { useLayoutEffect_SAFE_FOR_SSR } from '@alfalab/hooks';

import { SIZE_TO_CLASSNAME_MAP } from '../../consts';
Expand Down Expand Up @@ -123,7 +124,7 @@ export const BaseSelect = forwardRef<unknown, ComponentProps>(
ModalMobile,
BottomSheet,
limitDynamicOptionGroupSize,
environment = isClient() ? window : undefined,
environment: environmentFromProps,
} = props;
const shouldSearchBlurRef = useRef(true);
const rootRef = useRef<HTMLDivElement>(null);
Expand All @@ -133,7 +134,8 @@ export const BaseSelect = forwardRef<unknown, ComponentProps>(
const searchRef = useRef<HTMLInputElement>(null);
const scrollableContainerRef = useRef<HTMLDivElement>(null);
const onOpenRef = useRef(onOpen);

const { environment: environmentFromConfig } = useCoreConfig();
const environment = environmentFromProps ?? environmentFromConfig;
const [searchState, setSearchState] = React.useState('');

const [search, setSearch] =
Expand Down
3 changes: 3 additions & 0 deletions packages/select/tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
"@alfalab/core-components-button/*": ["../button/src/*"],
"@alfalab/core-components-checkbox": ["../checkbox/src"],
"@alfalab/core-components-checkbox/*": ["../checkbox/src/*"],
"@alfalab/core-components-config": ["../config/src"],
"@alfalab/core-components-config/*": ["../config/src/*"],
"@alfalab/core-components-form-control": ["../form-control/src"],
"@alfalab/core-components-form-control/*": ["../form-control/src/*"],
"@alfalab/core-components-input": ["../input/src"],
Expand All @@ -43,6 +45,7 @@
{ "path": "../bottom-sheet/tsconfig.build.json" },
{ "path": "../button/tsconfig.build.json" },
{ "path": "../checkbox/tsconfig.build.json" },
{ "path": "../config/tsconfig.build.json" },
{ "path": "../form-control/tsconfig.build.json" },
{ "path": "../input/tsconfig.build.json" },
{ "path": "../modal/tsconfig.build.json" },
Expand Down
3 changes: 3 additions & 0 deletions packages/select/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
"@alfalab/core-components-button/*": ["../button/src/*"],
"@alfalab/core-components-checkbox": ["../checkbox/src"],
"@alfalab/core-components-checkbox/*": ["../checkbox/src/*"],
"@alfalab/core-components-config": ["../config/src"],
"@alfalab/core-components-config/*": ["../config/src/*"],
"@alfalab/core-components-form-control": ["../form-control/src"],
"@alfalab/core-components-form-control/*": ["../form-control/src/*"],
"@alfalab/core-components-input": ["../input/src"],
Expand Down Expand Up @@ -46,6 +48,7 @@
{ "path": "../bottom-sheet/tsconfig.build.json" },
{ "path": "../button/tsconfig.build.json" },
{ "path": "../checkbox/tsconfig.build.json" },
{ "path": "../config/tsconfig.build.json" },
{ "path": "../form-control/tsconfig.build.json" },
{ "path": "../input/tsconfig.build.json" },
{ "path": "../modal/tsconfig.build.json" },
Expand Down