Skip to content
This repository has been archived by the owner on Mar 17, 2024. It is now read-only.

Commit

Permalink
BREAKING CHANGE: DropdownButton and DropdownMenuItem title now is ref
Browse files Browse the repository at this point in the history
fix: typo MutliDropdownController to MultiDropdownController
build: v0.7.2
  • Loading branch information
Arenukvern committed Feb 20, 2021
1 parent 72d0121 commit 8c4c472
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 39 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## 0.7.0

### feat: MutliDropdownButton
### feat: MultiDropdownButton

Usage:

Expand All @@ -14,7 +14,7 @@ const IndexedText {
}


const multiDropdownController = new MutliDropdownFieldController<IndexedText>(
const multiDropdownController = new MultiDropdownFieldController<IndexedText>(
{ keyofValue: 'id' }
)
```
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ const IndexedText {
}


const multiDropdownController = new MutliDropdownFieldController<IndexedText>(
const multiDropdownController = new MultiDropdownFieldController<IndexedText>(
{ keyofValue: 'id' }
)
```
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@xsoulspace/vue_flutter_tailwind",
"description": "Vue3 styled like Flutter with Tailwind CSS",
"version": "0.7.1",
"version": "0.7.2",
"private": false,
"author": {
"name": "Anton Malofeev",
Expand Down
30 changes: 15 additions & 15 deletions src/abstract/DropdownFieldController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ interface DropdownButtonAbstractI<TValue> {

export interface MultiDropdownButtonI<
TValue,
TKeyValue extends MutliDropdownSelectedItemI<TValue>
TKeyValue extends MultiDropdownSelectedItemI<TValue>
> extends DropdownButtonAbstractI<TValue> {
controller: MutliDropdownFieldController<TValue, TKeyValue>
controller: MultiDropdownFieldController<TValue, TKeyValue>
onCreateNew?: Maybe<
({ editingText }: { editingText: string }) => Promise<void>
>
Expand All @@ -44,35 +44,35 @@ export interface DropdownFieldControllerI<I>
value?: Maybe<I>
}

export interface MutliDropdownFieldControllerI<TValue>
export interface MultiDropdownFieldControllerI<TValue>
extends DropdownFieldControllerAbstractI {
value?: Maybe<TValue>[]
keyofValue: keyof TValue
}
/**
* This class provides a way to create selected items from
* outside for`{MutliDropdownFieldController.value}`
* outside for`{MultiDropdownFieldController.value}`
*/
export type MutliDropdownSelectedItemI<TValue> = {
export type MultiDropdownSelectedItemI<TValue> = {
key: TValue[keyof TValue] | string
value: TValue
}
/**
* This is typeguard for MutliDropdownSelectedItemI interface
* This is typeguard for MultiDropdownSelectedItemI interface
*/
export const isMutliDropdownSelectedItem = <
export const isMultiDropdownSelectedItem = <
TValue,
TKeyValue extends MutliDropdownSelectedItemI<TValue>
TKeyValue extends MultiDropdownSelectedItemI<TValue>
>(
arg: Record<string, unknown>
): arg is TKeyValue => {
return 'key' in arg && 'value' in arg
}
/**
* This class provides a way to create selected items from
* `{ItemBuilder}` for``{MutliDropdown}``
* `{ItemBuilder}` for``{MultiDropdown}``
*/
export interface MutliDropdownSelectedValueI<TValue> {
export interface MultiDropdownSelectedValueI<TValue> {
selected: boolean
value: TValue
}
Expand Down Expand Up @@ -135,9 +135,9 @@ export class DropdownFieldController<
type TKeyValueIndex = number

// TODO: add properties
export class MutliDropdownFieldController<
export class MultiDropdownFieldController<
TValue,
TKeyValue extends MutliDropdownSelectedItemI<TValue> = MutliDropdownSelectedItemI<TValue>
TKeyValue extends MultiDropdownSelectedItemI<TValue> = MultiDropdownSelectedItemI<TValue>
> extends DropdownFieldControllerAbstract {
private _reactVal: {
val: Maybe<TKeyValue>[]
Expand All @@ -151,7 +151,7 @@ export class MutliDropdownFieldController<
maxLines,
maxLength,
keyofValue,
}: MutliDropdownFieldControllerI<TValue>) {
}: MultiDropdownFieldControllerI<TValue>) {
super({
maxLength,
maxLines,
Expand All @@ -167,11 +167,11 @@ export class MutliDropdownFieldController<
toKeyValues({ values }: { values: Maybe<TValue>[] }): Maybe<TKeyValue>[] {
return values.filter(isNotNull).map((value) => {
const key = value[this.keyofValue]
const keyValue: MutliDropdownSelectedItemI<TValue> = {
const keyValue: MultiDropdownSelectedItemI<TValue> = {
key,
value,
}
if (isMutliDropdownSelectedItem<TValue, TKeyValue>(keyValue)) {
if (isMultiDropdownSelectedItem<TValue, TKeyValue>(keyValue)) {
return keyValue
}
return
Expand Down
4 changes: 2 additions & 2 deletions src/abstract/DropdownMenuItem.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Component } from 'vue'
import { Component, Ref } from 'vue'
import { Maybe } from './BasicTypes'

// The key must be assigned to let compare items automatically
export type DropdownMenuItemConstructor<I> = {
widget: Component
value?: Maybe<I>
key: string
title: string
title: Ref<string>
}
4 changes: 2 additions & 2 deletions src/components/DropdownButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export const DropdownButton = <
items.find((el) => el.key == controller.key.value)
)
// init
textFieldController.text.value = selectedItem.value?.title ?? ''
textFieldController.text.value = selectedItem.value?.title.value ?? ''
const isMenuOpened = ref(false)

const itemsDropdown = defineComponent({
Expand Down Expand Up @@ -91,7 +91,7 @@ export const DropdownButton = <
if (item == null) return Container({})
controller.value = item.value
controller.key.value = item.key
textFieldController.text.value = item.title
textFieldController.text.value = item.title.value
isMenuOpened.value = false
if (onChanged && item.value) {
onChanged(item.value, oldValue)
Expand Down
4 changes: 2 additions & 2 deletions src/components/DropdownMenuItem.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, defineComponent, h } from 'vue'
import { Component, defineComponent, h, Ref } from 'vue'
import { Alignment } from '../abstract/Alignment'
import { Maybe } from '../abstract/BasicTypes'
import { DropdownMenuItemConstructor } from '../abstract/DropdownMenuItem'
Expand All @@ -11,7 +11,7 @@ interface DropdownMenuItemI<I> {
key: string
onTap?: Maybe<CallableFunction>
value: Maybe<I>
title: string
title: Ref<string>
}

export const DropdownMenuItem = <I extends unknown>({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import { BoxDecoration } from '../abstract/BoxDecoration'
import { BoxShadow } from '../abstract/BoxShadow'
import { Colors } from '../abstract/Colors'
import {
isMutliDropdownSelectedItem,
isMultiDropdownSelectedItem,
MultiDropdownButtonI,
MutliDropdownSelectedItemI,
MutliDropdownSelectedValueI,
MultiDropdownSelectedItemI,
MultiDropdownSelectedValueI,
} from '../abstract/DropdownFieldController'
import { DropdownMenuItemConstructor } from '../abstract/DropdownMenuItem'
import { EdgeInsets, EdgeInsetsStep } from '../abstract/EdgeInsets'
Expand Down Expand Up @@ -46,7 +46,7 @@ import { Wrap } from './Wrap'
* }
*
*
* const multiDropdownController = new MutliDropdownFieldController<IndexedText>(
* const multiDropdownController = new MultiDropdownFieldController<IndexedText>(
* { keyofValue: 'id' }
* )
* ```
Expand Down Expand Up @@ -81,7 +81,7 @@ export const MultiDropdownButton = <
| boolean
| { [prop: string]: any }
| { [prop: number]: any },
TKeyValue extends MutliDropdownSelectedItemI<TValue>
TKeyValue extends MultiDropdownSelectedItemI<TValue>
>({
items,
elevation,
Expand Down Expand Up @@ -129,18 +129,18 @@ export const MultiDropdownButton = <
item,
key,
}: {
item: MutliDropdownSelectedValueI<DropdownMenuItemConstructor<TValue>>
item: MultiDropdownSelectedValueI<DropdownMenuItemConstructor<TValue>>
key: TKeyValue['key'] | string
}) => {
const val = item.value.value
if (val != null) {
const selectedItem: MutliDropdownSelectedItemI<TValue> = {
const selectedItem: MultiDropdownSelectedItemI<TValue> = {
key,
value: val,
}

const selectedItemIndex = controller.valueIndexesByKeyMap.get(key)
if (isMutliDropdownSelectedItem<TValue, TKeyValue>(selectedItem)) {
if (isMultiDropdownSelectedItem<TValue, TKeyValue>(selectedItem)) {
if (selectedItemIndex != null && selectedItemIndex >= 0) {
controller.keyValue.splice(selectedItemIndex, 1, selectedItem)
} else {
Expand Down Expand Up @@ -170,7 +170,7 @@ export const MultiDropdownButton = <
},
setup() {
const effectiveItems = computed<
MutliDropdownSelectedValueI<DropdownMenuItemConstructor<TValue>>[]
MultiDropdownSelectedValueI<DropdownMenuItemConstructor<TValue>>[]
>(() =>
items
.filter((el) => {
Expand Down
2 changes: 1 addition & 1 deletion src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export * from './ListViewItem'
export * from './Margin'
export * from './Material'
export * from './MouseRegion'
export * from './MutliDropdownButton'
export * from './MultiDropdownButton'
export * from './Navigation'
export * from './Opacity'
export * from './Padding'
Expand Down
8 changes: 4 additions & 4 deletions src/example/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
ListView,
MainAxisAlignment,
MouseRegion,
MutliDropdownFieldController,
MultiDropdownFieldController,
Padding,
Row,
Scaffold,
Expand Down Expand Up @@ -111,7 +111,7 @@ export const WrapperApp = () => {
}),
value: el,
key: el.id.toString(),
title: el.text,
title: ref(el.text),
})
),
controller: dropdownFieldController,
Expand Down Expand Up @@ -181,7 +181,7 @@ export const WrapperApp = () => {
})
),
})
const multiDropdownController = new MutliDropdownFieldController<IndexedText>(
const multiDropdownController = new MultiDropdownFieldController<IndexedText>(
{ keyofValue: 'id' }
)
watch(
Expand Down Expand Up @@ -223,7 +223,7 @@ export const WrapperApp = () => {
}),
value: el,
key: el.id.toString(),
title: el.text,
title: ref(el.text),
})
),
}),
Expand Down

0 comments on commit 8c4c472

Please sign in to comment.