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

Commit 1d69776

Browse files
authored
Merge pull request #85
Icon only add button
2 parents b0829a1 + 45283d6 commit 1d69776

File tree

5 files changed

+80
-13
lines changed

5 files changed

+80
-13
lines changed

package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,13 @@
7575
},
7676
"resolutions": {
7777
"trim": ">=0.0.3",
78-
"tar": ">=6.1.2",
78+
"tar": ">=6.1.11",
7979
"prismjs": ">=1.24.0",
8080
"glob-parent": ">=5.1.2",
8181
"postcss": ">=8.2.10",
8282
"browserslist": ">=4.16.5",
83-
"ws": ">=7.4.6"
83+
"ws": ">=7.4.6",
84+
"path-parse": "1.0.7"
8485
},
8586
"husky": {
8687
"hooks": {

src/Card.re

+2
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ module Tabbed = {
4747
~children=<Empty />,
4848
~activeTabId: string,
4949
~tabs: array(Tabs.t),
50+
~addButtonText,
5051
~onAdd=?,
5152
~onMove=?,
5253
~onOpen=?,
@@ -66,6 +67,7 @@ module Tabbed = {
6667
activeTabId
6768
theme
6869
depth
70+
?addButtonText
6971
?onAdd
7072
?onMove
7173
?onOpen

src/Tabs.re

+19-3
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,14 @@ type action =
8686

8787
module AddTab = {
8888
[@react.component]
89-
let make = (~dispatch: action => unit, ~depth: int, ~standalone, ~theme) => {
89+
let make =
90+
(
91+
~dispatch: action => unit,
92+
~depth: int,
93+
~standalone,
94+
~theme,
95+
~title=Some("New"),
96+
) => {
9097
/*
9198
The index below is technically incorrect. But by adding it to the
9299
list of draggable items, it means the placeholder will be correctly
@@ -103,7 +110,9 @@ module AddTab = {
103110
}
104111
onClick={_ => Add(Helpers.create("New tab"))->dispatch}>
105112
<span className=Styles.addIcon> <Icons.Plus /> </span>
106-
<span className=Styles.addText> "Add"->React.string </span>
113+
{Belt.Option.mapWithDefault(title, <Empty />, x =>
114+
<span className=Styles.addText> x->React.string </span>
115+
)}
107116
</div>
108117
</Dnd.Draggable>;
109118
};
@@ -189,6 +198,7 @@ let make =
189198
~onOpen=?,
190199
~onRename=?,
191200
~onClose=?,
201+
~addButtonText=?,
192202
~onDuplicate=?,
193203
) => {
194204
let onDispatch = action =>
@@ -252,7 +262,13 @@ let make =
252262
)
253263
->React.array}
254264
{onAdd->Belt.Option.isSome
255-
<&&> <AddTab theme depth standalone dispatch=onDispatch />}
265+
<&&> <AddTab
266+
theme
267+
depth
268+
standalone
269+
dispatch=onDispatch
270+
title=addButtonText
271+
/>}
256272
</div>
257273
</Dnd.Droppable>
258274
</Dnd.Context>

stories/tabs.stories.js

+48
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ export const tabs = () => {
8787
type Tabs: (
8888
~activeTabId: string;
8989
~depth: option(int);
90+
~addButtonText: option(string); // Defaults to "New"
9091
~onAdd: option(t -> unit);
9192
~onClose: option(string -> unit);
9293
~onDuplicate: option(string -> unit);
@@ -160,6 +161,53 @@ type Tabs: (
160161
</p>
161162
</Tabs>
162163
</div>
164+
<h3>All Functionality Enabled - hiding add text</h3>
165+
<div style={smallCardContainerWide}>
166+
<Tabs
167+
addButtonText={null}
168+
onAdd={(newTab) => {
169+
setTabs((tabs) => Helpers.add(tabs, newTab))
170+
setActiveTabId(newTab.id)
171+
}}
172+
onOpen={setActiveTabId}
173+
onMove={([from, to]) => {
174+
setTabs(Helpers.move(tabs, from, to))
175+
}}
176+
onRename={(x) => {
177+
setTabs((tabs) => Helpers.update(tabs, x))
178+
}}
179+
onClose={(x) => {
180+
const tabIdx = tabs.findIndex((y) => y.id === x)
181+
console.log(tabIdx, x)
182+
if (tabs[tabIdx + 1]) {
183+
setActiveTabId(tabs[tabIdx + 1].id)
184+
} else if (tabs[tabIdx - 1]) {
185+
setActiveTabId(tabs[tabIdx - 1].id)
186+
} else {
187+
setActiveTabId('')
188+
}
189+
setTabs((tabs) => Helpers.removeById(tabs, x))
190+
}}
191+
onDuplicate={(x) => {
192+
const [newTabs, newId] = Helpers.duplicateById(
193+
tabs,
194+
x
195+
)
196+
setActiveTabId(newId)
197+
setTabs(newTabs)
198+
}}
199+
tabs={tabs}
200+
activeTabId={activeTabId}
201+
depth={2}
202+
theme={theme}
203+
>
204+
<h2>Tabs</h2>
205+
<p>
206+
Active Tab:{' '}
207+
{tabs.find((x) => x.id === activeTabId).title}
208+
</p>
209+
</Tabs>
210+
</div>
163211
<h3>No Duplication</h3>
164212
<div style={smallCardContainerWide}>
165213
<Tabs

yarn.lock

+8-8
Original file line numberDiff line numberDiff line change
@@ -10619,10 +10619,10 @@ path-key@^3.0.0, path-key@^3.1.0:
1061910619
resolved "https://registry.yarnpkg.com/path-key/-/path-key-3.1.1.tgz#581f6ade658cbba65a0d3380de7753295054f375"
1062010620
integrity sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==
1062110621

10622-
path-parse@^1.0.6:
10623-
version "1.0.6"
10624-
resolved "https://registry.yarnpkg.com/path-parse/-/path-parse-1.0.6.tgz#d62dbb5679405d72c4737ec58600e9ddcf06d24c"
10625-
integrity sha512-GSmOT2EbHrINBf9SR7CDELwlJ8AENk3Qn7OikK4nFYAu3Ote2+JYNVvkpAEQm3/TLNEJFD/xZJjzyxg3KBWOzw==
10622+
path-parse@1.0.7, path-parse@^1.0.6:
10623+
version "1.0.7"
10624+
resolved "https://registry.yarnpkg.com/path-parse/-/path-parse-1.0.7.tgz#fbc114b60ca42b30d9daf5858e4bd68bbedb6735"
10625+
integrity sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==
1062610626

1062710627
path-starts-with@^1.0.0:
1062810628
version "1.0.0"
@@ -13625,10 +13625,10 @@ tapable@^2.0.0:
1362513625
resolved "https://registry.yarnpkg.com/tapable/-/tapable-2.2.0.tgz#5c373d281d9c672848213d0e037d1c4165ab426b"
1362613626
integrity sha512-FBk4IesMV1rBxX2tfiK8RAmogtWn53puLOQlvO8XuwlgxcYbP4mVPS9Ph4aeamSyyVjOl24aYWAuc8U5kCVwMw==
1362713627

13628-
tar@>=6.1.2, tar@^6.0.2:
13629-
version "6.1.6"
13630-
resolved "https://registry.yarnpkg.com/tar/-/tar-6.1.6.tgz#c23d797b0a1efe5d479b1490805c5443f3560c5d"
13631-
integrity sha512-oaWyu5dQbHaYcyZCTfyPpC+VmI62/OM2RTUYavTk1MDr1cwW5Boi3baeYQKiZbY2uSQJGr+iMOzb/JFxLrft+g==
13628+
tar@>=6.1.11, tar@^6.0.2:
13629+
version "6.1.11"
13630+
resolved "https://registry.yarnpkg.com/tar/-/tar-6.1.11.tgz#6760a38f003afa1b2ffd0ffe9e9abbd0eab3d621"
13631+
integrity sha512-an/KZQzQUkZCkuoAA64hM92X0Urb6VpRhAFllDzz44U2mcD5scmT3zBc4VgVpkugF580+DQn8eAFSyoQt0tznA==
1363213632
dependencies:
1363313633
chownr "^2.0.0"
1363413634
fs-minipass "^2.0.0"

0 commit comments

Comments
 (0)