Pen Settings

HTML

CSS

CSS Base

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

Vue

              
                <script setup>
import { ref, reactive, computed } from "vue"

const message = ref("")
const messageFor = ref(1)
const wordCount = computed(() =>
                  message.value
                         .split(' ')
                         .filter(t => t !== '')
                         .length)
const writing = computed(() =>
                wordCount.value > 0 ? true : false)

const messages = reactive([
  [0,"hello there, so good to see you here, glad that you could make it."],
  [1,"thanks, this is a neat place to be"],
  [0,"hell yeah!"]])

const messageList = ref(null)
const goDown = () =>
  { messageList.value.scrollTop =
      messageList.value.scrollHeight - messageList.value.clientHeight }
const changeSide = () =>
  { messageFor.value = messageFor.value === 1 ? 0 : 1 }
const send = () =>
  { if (message.value.trim().length < 1) return
    messages.push([messageFor.value, message.value])
    message.value = ""
    goDown() }
</script>

<template>
  <div class="screen">
    <div class="messages" ref="messageList">
      <template v-for="msg in messages">
        <div :class="`message ${msg[0] === 0 ? 'left' : 'right'}`">
          <p>{{msg[1]}}</p>
        </div>
      </template>
      <template v-if="writing">
        <div :class="`message template ${messageFor === 0 ? 'left' : 'right'}`">
          <div>
            <div
             v-for="_ in wordCount"
             class="dot"></div>
          </div>
          <button @click="changeSide" title="change side">
            {{messageFor === 0 ? '🠖' : '🠔'}}
          </button>
        </div>
      </template>
    </div> <!-- messages -->
    <div class="bottom">
      <input
       v-model="message"
       type="text"
       @keyup.enter="send"
       @keydown="goDown"
       placeholder="Your messasge...">
      <button @click="send">
        <svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" fill="#ffffff" viewBox="0 0 256 256"><path d="M223.69,42.18l-58.22,192a8,8,0,0,1-14.92,1.25L108,148,20.58,105.45a8,8,0,0,1,1.25-14.92l192-58.22A8,8,0,0,1,223.69,42.18Z" opacity="0.2"></path><path d="M227.32,28.68a16,16,0,0,0-15.66-4.08l-.15,0L19.57,82.84a16,16,0,0,0-2.49,29.8L102,154l41.3,84.87A15.86,15.86,0,0,0,157.74,248q.69,0,1.38-.06a15.88,15.88,0,0,0,14-11.51l58.2-191.94c0-.05,0-.1,0-.15A16,16,0,0,0,227.32,28.68ZM157.83,231.85l-.05.14,0-.07-40.06-82.3,48-48a8,8,0,0,0-11.31-11.31l-48,48L24.08,98.25l-.07,0,.14,0L216,40Z"></path></svg>
      </button>
    </div> <!-- bottom -->
  </div> <!-- screen -->
</template>

<style lang="stylus">
body
  height 100vh
  width 100vw
  margin 0
  padding 0
  display flex
  flex-direction column
  justify-content center
  align-items center
  font-family sans-serif
  background #1e2030

.screen
  border 10px solid #181926
  outline 1px solid #ffffff20
  border-radius 16px
  overflow clip
  height 80vmin
  width 45vmin
  display flex
  flex-direction column
  background #24273a
  
.messages
  flex-grow 1
  display flex
  flex-direction column
  padding 1rem
  gap 1rem
  overflow-y scroll
  overflow-x clip

.message
  max-width 60%
  width fit-content
  height fit-content
  padding .5rem
  color white
  outline 1px solid #ffffff20
  animation appear .25s
  transition background .5s, border-radius .5s
  position relative
  word-break break-word
  
  &.left
    border-radius 16px 16px 16px 4px
    background #7c7f93
    margin 0 auto 0 0

    button
      right -1.75rem
  &.right
    margin 0 0 0 auto
    border-radius 16px 16px 4px 16px
    background #8839ef

    button
      left -1.75rem
  &.template
    opacity 90%
    display flex
    flex-direction column
    
    button
      background transparent
      border none
      font-weight bold
      color white
      display block
      position absolute
      border-radius 100px
      height 1.5rem
      width 1.5rem
      opacity 70%
      
      &:hover
        background #ffffff40
  
.dot
  background #cad3f5
  opacity 80%
  height 1rem
  width 1rem
  border-radius 1000px
  display inline-block
  margin .1rem
  animation glow 2s infinite, appear .25s

@keyframes appear
  from
    scale 0 0.75
  to
    scale 1 1
@keyframes glow
  0%
    background #cad3f5
    scale 100%
  50%
    background #a5adcb
    scale 90%
  100%
    background #cad3f5
    scale 100%
  
.bottom
  background linear-gradient(transparent, #363a4f 16px)
  display flex
  flex-direction row
  padding 0
  padding-top 16px
  gap 0
  
  input
    flex-grow 1
    background transparent
    color #cad3f5
    background transparent
    border 2px solid transparent
    padding .5rem
    border-radius 0
  button
    background transparent
    border none
    color black
    border-radius 0px
    font-weight bold
    opacity 80%
    transition opacity .25s
    
    &:hover
      opacity 100%
    
    svg
      scale 70%
      
</style>
              
            
!
999px

Console