git ssb

16+

Dominic / patchbay



Commit 60e60ca4a797710df7dce064463d8f89346ea260

channel picker styling, addition of mutant to manage state

mix irving committed on 2/6/2017, 12:39:33 AM
Parent: 164ff0f5cab3f959bf2612a84138a9f46df599ee

Files changed

modules_basic/compose.jschanged
modules_basic/compose.mcsschanged
modules_basic/compose.jsView
@@ -1,7 +1,8 @@
11 'use strict'
22 const fs = require('fs')
33 const h = require('../h')
4 +const { Value, when } = require('@mmckegg/mutant')
45 const mentions = require('ssb-mentions')
56
67 exports.needs = {
78 suggest_mentions: 'map', //<-- THIS MUST BE REWRITTEN
@@ -41,58 +42,56 @@
4142 }
4243 }
4344 opts.prepublish = opts.prepublish || id
4445
45- var actions
46 + const isExpanded = Value(opts.shrink === false)
4647
4748 var textArea = h('textarea', {
4849 placeholder: opts.placeholder || 'Write a message'
4950 })
5051
5152 var channelInput = h('input.channel', {
52- placeholder: '#channel',
53 + placeholder: '#channel (optional)',
5354 value: meta.channel ? `#${meta.channel}` : '',
54- disabled: meta.channel ? true : false
55 + disabled: meta.channel ? true : false,
56 + title: meta.channel ? 'Reply is in same channel as original message' : '',
5557 })
5658
57- channelInput.addEventListener('keydown', function (e) {
58- console.log(e)
59- if (this.value.startsWith('#') && this.value.length === 1) {
60- this.value = ''
61- return
62- }
63- if (this.value.startsWith('#')) return
64- this.value = `#${this.value}`
59 + channelInput.addEventListener('keyup', (e) => {
60 + e.target.value = e.target.value
61 + .replace(/^#*([\w@%&])/, '#$1')
6562 })
6663
6764 if(opts.shrink !== false) {
65 + isExpanded.set(false)
6866 var blur
67 +
6968 textArea.addEventListener('focus', () => {
7069 clearTimeout(blur)
7170 if(!textArea.value) {
72- composer.className = 'Compose -expanded'
71 + isExpanded.set(true)
7372 }
7473 })
7574 textArea.addEventListener('blur', () => {
7675 //don't shrink right away, so there is time
7776 //to click the publish button.
7877 clearTimeout(blur)
7978 blur = setTimeout(() => {
8079 if(textArea.value) return
81- composer.className = 'Compose -contracted'
80 + isExpanded.set(false)
8281 }, 300)
8382 })
8483 channelInput.addEventListener('focus', () => {
8584 clearTimeout(blur)
8685 if (!textArea.value) {
87- composer.className = 'Compose -expanded'
86 + isExpanded.set(true)
8887 }
8988 })
9089 channelInput.addEventListener('blur', () => {
9190 clearTimeout(blur)
9291 blur = setTimeout(() => {
9392 if (textArea.value || channelInput.value) return
94- composer.className = 'Compose -contracted'
93 + isExpanded.set(false)
9594 }, 300)
9695 })
9796 }
9897
@@ -148,28 +147,25 @@
148147
149148 var embed = file.type.indexOf('image/') === 0 ? '!' : ''
150149
151150 textArea.value += embed + '['+file.name+']('+file.link+')'
152- composer.className = 'Compose -expanded'
151 + isExpanded.set(true)
153152 console.log('added:', file)
154153 })
155154 var publishBtn = h('button', {'ev-click': publish}, 'Publish' )
156- var actions = h('section.actions', [
157- fileInput, publishBtn
158- ])
155 + var actions = h('section.actions', [ fileInput, publishBtn ])
159156
160157 api.build_suggest_box(textArea, api.suggest_mentions)
161158 api.build_suggest_box(channelInput, api.suggest_channel)
162159
163160 var composer = h('Compose', {
164- className: opts.shrink === false ? '-expanded' : '-contracted'
161 + classList: [ when(isExpanded, '-expanded', '-contracted') ]
165162 }, [
163 + channelInput,
166164 textArea,
167- channelInput,
168165 actions
169166 ])
170167
171-
172168 return composer
173169 }
174170
175171 }
modules_basic/compose.mcssView
@@ -5,17 +5,25 @@
55 padding: 1rem .5rem 1rem 7.3rem
66
77 textarea {
88 border: 1px solid gainsboro
9 + border-top-left-radius: 0
10 + border-top-right-radius: 0
911 }
1012
1113 input.channel {
1214 border: 1px solid gainsboro
15 + border-bottom: none
16 + border-bottom-left-radius: 0
17 + border-bottom-right-radius: 0
1318 padding: .5rem
14- margin-top: 1rem
1519
20 + :focus {
21 + outline: none
22 + box-shadow: none
23 + }
1624 :disabled {
17- background-color: #e5e5e5
25 + background-color: #f1f1f1
1826 cursor: not-allowed
1927 }
2028 }
2129

Built with git-ssb-web