-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
169 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
name: Publish core-config | ||
|
||
on: | ||
workflow_dispatch: | ||
inputs: | ||
version: | ||
description: 'Введите версию x.x.x' | ||
required: true | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Check permissions | ||
if: ${{ contains(fromJSON('["reme3d2y","hextion","SiebenSieben","fulcanellee"]'), github.actor) == false }} | ||
uses: actions/github-script@v6 | ||
with: | ||
script: | | ||
core.setFailed("you don't have permission to run this workflow!"); | ||
- uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: '20.x' | ||
registry-url: 'https://registry.npmjs.org' | ||
|
||
- name: Install dependencies | ||
run: yarn --pure-lockfile | ||
|
||
- name: Build app | ||
run: | | ||
cd ./external/core-config | ||
yarn build | ||
- name: Set version | ||
if: success() | ||
run: | | ||
cd ./external/core-config | ||
git config user.name core-ds-bot | ||
git config user.email [email protected] | ||
yarn --new-version version ${{ github.event.inputs.version }} | ||
git push | ||
- name: Publish | ||
if: success() | ||
run: | | ||
cd ./external/core-config | ||
npm publish | ||
env: | ||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2024 core-ds | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"name": "@alfalab/core-config", | ||
"version": "0.0.0", | ||
"description": "Глобальный конфиг для настройки core-components", | ||
"main": "./dist/index.js", | ||
"types": "./dist/index.d.ts", | ||
"license": "MIT", | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"files": [ | ||
"/dist" | ||
], | ||
"scripts": { | ||
"build": "tsc" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { createContext, useContext } from 'react'; | ||
|
||
export type CoreConfigContext = { | ||
breakpoint: number; | ||
ssrView: 'desktop' | 'mobile'; | ||
}; | ||
|
||
export const CoreConfigContext = createContext<CoreConfigContext>({ | ||
breakpoint: 1024, | ||
ssrView: 'desktop', | ||
}); | ||
|
||
export const useCoreConfig = (overrides: Partial<CoreConfigContext> = {}) => { | ||
const config = useContext(CoreConfigContext); | ||
|
||
Object.entries(overrides).forEach(([key, value]) => { | ||
if (value === undefined) { | ||
delete overrides[key as keyof typeof overrides]; | ||
} | ||
}); | ||
|
||
return { | ||
...config, | ||
...overrides, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './CoreConfigContext'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "es2016", | ||
"jsx": "react", | ||
"module": "commonjs", | ||
"declaration": true, | ||
"outDir": "./dist", | ||
"declarationDir": "./dist", | ||
"esModuleInterop": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"strict": true, | ||
"skipLibCheck": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './Component'; | ||
export * from './useMatchMedia'; | ||
export * from './useIsDesktop'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { useCoreConfig } from '@alfalab/core-config'; | ||
import { useMatchMedia } from './useMatchMedia'; | ||
|
||
export function useIsDesktop(breakpoint?: number, defaultValue?: boolean | (() => boolean)) { | ||
let ssrView; | ||
|
||
if (typeof defaultValue === 'boolean') { | ||
ssrView = defaultValue ? 'desktop' : 'mobile'; | ||
} else if (typeof defaultValue === 'function') { | ||
ssrView = defaultValue() ? 'desktop' : 'mobile'; | ||
} | ||
|
||
const config = useCoreConfig({ breakpoint, ssrView }); | ||
|
||
const query = `(min-width: ${config.breakpoint}px)`; | ||
|
||
const [isDesktop] = useMatchMedia(query, config.ssrView === 'desktop'); | ||
|
||
return isDesktop; | ||
} |