-
Notifications
You must be signed in to change notification settings - Fork 21
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
3 changed files
with
46 additions
and
4 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
packages/x-components/src/components/snippet-config-provider.vue
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,37 @@ | ||
<script lang="ts"> | ||
import { defineComponent, provide, ref } from 'vue'; | ||
import { useNoElementRender } from '../composables'; | ||
import { baseSnippetConfig } from '../views/base-config'; | ||
import { SnippetConfig } from '../x-installer'; | ||
/**. | ||
* SnippetConfig Provider component. | ||
* This component provides a SnippetConfig object and a function that is responsible for mutating the SnippetConfig when we need to update its data from an injector component. | ||
* | ||
* @public | ||
*/ | ||
export default defineComponent({ | ||
name: 'SnippetConfigProvider', | ||
setup(_, { slots }) { | ||
const snippetConfig = ref(baseSnippetConfig); | ||
/** | ||
* Sets or updates the snippet config. | ||
* | ||
* @param config - A part or all the snippet config. | ||
* | ||
* @public | ||
*/ | ||
function setSnippetConfig(config: Partial<SnippetConfig>): void { | ||
Object.assign(snippetConfig.value, config); | ||
} | ||
provide('snippetConfig', { | ||
snippetConfig, | ||
setSnippetConfig | ||
}); | ||
return () => useNoElementRender(slots); | ||
} | ||
}); | ||
</script> |
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