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

Support dynamic CSS classes (1 per line) #6

Open
qoke opened this issue Apr 28, 2017 · 3 comments
Open

Support dynamic CSS classes (1 per line) #6

qoke opened this issue Apr 28, 2017 · 3 comments

Comments

@qoke
Copy link

qoke commented Apr 28, 2017

Feature request for supporting the ability to give different CSS classes per text entry item.

Example:

<vue-typer
  :text='["1st text","2nd text","3rd text"]'
  :styles='["first","second","third"]'
></vue-typer>

New style would be applied before typing on a new line begins.

@cngu
Copy link
Owner

cngu commented Apr 29, 2017

It's not clear whether those "styles" would be applied on the text or caret, and during which phase of typing. I'd prefer to avoid multiple/complex props and keep the styling in CSS,

We could support this without breaking the existing customizable CSS selector structure (but perhaps making it a bit awkward) by adding a `text-${index}` class to vue-typer signifying the current text item index being typed.

Something like: .vue-typer.text-0 > .custom.char > etc.

@jnsprnw
Copy link

jnsprnw commented Dec 11, 2019

A bit late but I solved it in a bit hacky way. In my version, the class is the lowercase version of the text.

<vue-typer
  :text="strings"
  :class="klass"
  @erased='onErased' />
function getNextElement (arr, i) {
  if (i === arr.length - 1) {
    return arr[0]
  } else {
    return arr[i + 1]
  }
}

export default {
  data () {
    return {
      strings: ['Foo', 'Bar'],
      klass: 'policy'
    }
  },
  components: {
    VueTyper
  },
  methods: {
    onErased (erasedString) {
      const i = this.strings.indexOf(erasedString)
      this.klass = getNextElement(this.strings, i).toLowerCase()
    }
  }
}
.vue-typer {
  &.foo .custom.char.typed {
    color: red;
  }

  &.bar .custom.char.typed {
    color: blue;
  }
}

Would be much nicer if vue-typer would emit an event beforeType with the upcoming string.

@liuxy0551
Copy link

liuxy0551 commented Dec 16, 2019

I think this is more better. I packaged the component, then you can define your font color in parent component. Child components will inherit parent component's font color.

<style lang="scss">
  .vue-typer {
    .typed {
      color: inherit;
    }
  }
</style>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants