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

Global options #1607

Closed
VividLemon opened this issue Nov 19, 2023 · 5 comments · Fixed by #1894
Closed

Global options #1607

VividLemon opened this issue Nov 19, 2023 · 5 comments · Fixed by #1894
Assignees
Labels
enhancement New feature or request

Comments

@VividLemon
Copy link
Member

A requirement of the library is to have a mechanism for creating "global options". Such as setting the default for props.

How exactly this would work idk yet.

But for instance this could be applied to having the nuxt module convert BLinks to NuxtLink (instead of RouterLink) by default, and other Nuxt specific options

This was referenced Nov 19, 2023
@VividLemon
Copy link
Member Author

Related to #1569

@VividLemon VividLemon added the enhancement New feature or request label Nov 19, 2023
@xvaara
Copy link
Contributor

xvaara commented Dec 1, 2023

@VividLemon maybe we use provide/inject, so have can have:
app.provide(GlobalOptionsKey,{nuxtLink: true})
const options = inject(GlobalOptionsKey, defaultOptions)
You could also provide different options to a subset of component tree with this approach.

@VividLemon
Copy link
Member Author

Inject would work well for orchestrating the defaults, but I'm not sure how you would get it to influence prop defaults.

The prop defaults needs to be an object literal. I don't think you're allowed to do some complex stuff.

Alternatively, merging the values at runtime could work. Though not super ideal as props have nice features like template unwrapping

@Kronhyx
Copy link

Kronhyx commented Jan 8, 2024

any update on this ?

@VividLemon
Copy link
Member Author

VividLemon commented Jan 20, 2024

Plan:

The system is inspired by https://vuetifyjs.com/en/features/global-configuration/#using-in-custom-components

The only con is that the default unwrapping of props in template is prevented. A minor nuisance, but unavoidable.

The way I believe this works is, the options from the configurator get placed in a provide(), the useDefaults accepts the components props & component name.

useDefaults is essentially

// Psuedo, there is a way to make the name and props object strongly typed. I assume all props would need to be ComponentProps.ts imported style, rather than some declared inline, and some not

export default (name: string, props: Record<string, unknown>) => {
  const injectedProps = inject('propsString')

  const mergeDefaults = computed(() => ({...injectedProps, ...props})) // Is props reactive?

  return mergeDefaults // Would reactive(mergeDefaults) be more straightforward to use?
}

Then each component would behave similarly to the steps shown in Vuetify

In addition, some research could be done into how Vuetfiy actually creates their "withDefaults" function, perhaps there's some better methods they use to take inspirations from. The nested defaults isn't addressed in the example I gave, but could be interesting

@VividLemon VividLemon self-assigned this Feb 7, 2024
VividLemon added a commit to VividLemon/bootstrap-vue-next that referenced this issue May 14, 2024
feat: implement global alias system fixes bootstrap-vue-next#1753

refactor: add bvn:: prefix to symbol keys

refactor: fix typo in 'BCardImageProps' change to 'BCardImgProps'
xvaara added a commit to xvaara/bootstrap-vue-next that referenced this issue May 22, 2024
* upstream/main: (23 commits)
  feat(BInput): Alias BFormInput to BInput
  fix(nuxt): dont teleport everything to #teleports -- selectively teleport based on body fixes bootstrap-vue-next#1898
  chore: release main
  feat(nuxt): allow passthrough options to createBootstrap plugin
  chore: release main (bootstrap-vue-next#1894)
  feat: implmenet a use defaults system WIP fixes bootstrap-vue-next#1607  (bootstrap-vue-next#1889)
  docs(BCheckBox*): Small changes to get documentation to parity (bootstrap-vue-next#1873)
  docs: Add component reference link in the page table of contents sidebar
  fixed BTableLite item _showDetails
  BTable delete selection when primary-key
  chore: release main
  feat(BTable): add change event -- replaces bv `modelValue` see bootstrap-vue-next#1775 (comment)
  chore: release main
  fix(BTable): selectedItems not clearing values properly fixes bootstrap-vue-next#1878 (bootstrap-vue-next#1879)
  chore: release main (bootstrap-vue-next#1874)
  fix(BTable): Pass through original records to slots in most circumstances (bootstrap-vue-next#1869)
  chore: release main (bootstrap-vue-next#1867)
  feat(BTable): Allow dot in sortby key
  fix: update dependencies to fix a bug in vue compiler (bootstrap-vue-next#1866)
  chore: release main (bootstrap-vue-next#1859)
  ...
Pequem pushed a commit to Pequem/bootstrap-vue-next that referenced this issue May 28, 2024
… (bootstrap-vue-next#1889)

feat: implement a use defaults system fixes bootstrap-vue-next#1607

feat: implement global alias system fixes bootstrap-vue-next#1753

refactor: add bvn:: prefix to symbol keys

refactor: fix typo in 'BCardImageProps' change to 'BCardImgProps'

feat(BFormInput)!: move props lazy, trim & number to v-model modifier. Modifiers should behave more like native Vue modifiers (number modifier with unparseable value returns value as is)

feat(BFormInput): type number performs the same as modifier

feat(BCarouselSlide): allow individual interval for slides

chore: update deps to fix some issues (nuxt useId, vue-tsc etc)

docs: global options, aliases

feat(nuxt): automatically globally set teleportTo to `#teleports`

feat(BreakpointProps)!: strongly type breakpoints. Instead of weak string | number => 1,2,3...'1','2','3'...

refactor(BRow): use script setup instead of options api

refactor(BCol): use script setup instead of options api
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

3 participants