-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(MdChips): add formatter for individual chips (#1339)
* feat(MdChips): formatter Formatter before chip insertion. Effects to insertion and duplicated-checking. fix #1288 * style(MdChips): always return a value * docs(Chips): fix `md-format` API description #1339 (comment) * docs(ChipsFormat): fix component name and example message * docs(ChipsFormat): `formatName` return result directly #1339 (comment) * style(MdChips): add a space before `if` statement #1339 (comment) * docs(Chips): better message for formatter #1339 (comment) * fix: code style
- Loading branch information
1 parent
d3953f7
commit 247a840
Showing
3 changed files
with
91 additions
and
11 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
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,47 @@ | ||
<template> | ||
<div> | ||
<md-chips class="md-primary" v-model="clubs" md-placeholder="Add club..." :md-format="toUppercase"> | ||
<label>La Liga Clubs</label> | ||
<div class="md-helper-text">Three uppercase letters</div> | ||
</md-chips> | ||
|
||
<md-chips class="md-primary" v-model="artists" md-placeholder="Add artist..." :md-format="formatName"> | ||
<label>Artists</label> | ||
<div class="md-helper-text">Try inserting `Eugène Ysaÿe`. The formatter will remove diacritics.</div> | ||
</md-chips> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
export default { | ||
name: 'Format', | ||
data: () => ({ | ||
clubs: [ | ||
'FCB', | ||
'MAD' | ||
], | ||
artists: [ | ||
'Claude Debussy', | ||
'Jules Massenet', | ||
'Gabriel Dupont', | ||
'Emma Bardac', | ||
'Mary Garden' | ||
] | ||
}), | ||
methods: { | ||
toUppercase (str) { | ||
str = str.replace(/\s/g, '').toUpperCase() | ||
if (str.length !== 3) return false | ||
return str | ||
}, | ||
formatName (str) { | ||
let words = str.split(' ').filter(str => str !== '') | ||
// remove accents / diacritics | ||
words = words.map(str => str.normalize('NFD').replace(/[\u0300-\u036f]/g, '')) | ||
// capitalize | ||
words = words.map(str => str[0].toUpperCase() + str.slice(1)) | ||
return words.join(' ') | ||
} | ||
} | ||
} | ||
</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