mirror of
https://github.com/penpot/penpot.git
synced 2025-04-02 01:51:33 -05:00
✨ Dashboard respect ratio for thumbnails
This commit is contained in:
parent
a4f32de9a1
commit
76a2f9bc8c
9 changed files with 57 additions and 53 deletions
frontend/src/app/main/ui
|
@ -25,4 +25,6 @@
|
||||||
position: relative;
|
position: relative;
|
||||||
grid-row: 1 / span 2;
|
grid-row: 1 / span 2;
|
||||||
padding: $s-16 $s-16 0 0;
|
padding: $s-16 $s-16 0 0;
|
||||||
|
overflow: hidden;
|
||||||
|
width: 100%;
|
||||||
}
|
}
|
||||||
|
|
|
@ -459,6 +459,7 @@
|
||||||
[:button
|
[:button
|
||||||
{:class (stl/css-case :selected selected? :library library-view?)
|
{:class (stl/css-case :selected selected? :library library-view?)
|
||||||
:ref node-ref
|
:ref node-ref
|
||||||
|
:title (:name file)
|
||||||
:draggable true
|
:draggable true
|
||||||
:on-click on-select
|
:on-click on-select
|
||||||
:on-key-down handle-key-down
|
:on-key-down handle-key-down
|
||||||
|
@ -634,20 +635,17 @@
|
||||||
[:& loading-placeholder]
|
[:& loading-placeholder]
|
||||||
|
|
||||||
(seq files)
|
(seq files)
|
||||||
[:ul
|
(for [slice (partition-all limit files)]
|
||||||
{:class (stl/css :grid-row)
|
[:ul {:class (stl/css :grid-row)}
|
||||||
:style {:grid-template-columns (str "repeat(" limit ", 1fr)")}}
|
(when @dragging?
|
||||||
|
[:li {:class (stl/css :grid-item)}])
|
||||||
(when @dragging?
|
(for [item slice]
|
||||||
[:li {:class (stl/css :grid-item)}])
|
[:& grid-item
|
||||||
|
{:file item
|
||||||
(for [item files]
|
:key (:id item)
|
||||||
[:& grid-item
|
:navigate? true
|
||||||
{:file item
|
:origin origin
|
||||||
:key (:id item)
|
:library-view? library-view?}])])
|
||||||
:navigate? true
|
|
||||||
:origin origin
|
|
||||||
:library-view? library-view?}])]
|
|
||||||
|
|
||||||
:else
|
:else
|
||||||
[:& empty-placeholder
|
[:& empty-placeholder
|
||||||
|
|
|
@ -6,17 +6,20 @@
|
||||||
|
|
||||||
@import "refactor/common-refactor.scss";
|
@import "refactor/common-refactor.scss";
|
||||||
|
|
||||||
|
$thumbnail-default-width: $s-252; // Default width
|
||||||
|
$thumbnail-aspect-ration: #{2 / 3}; // Ratio 2:3
|
||||||
|
|
||||||
.dashboard-grid {
|
.dashboard-grid {
|
||||||
font-size: $fs-14;
|
font-size: $fs-14;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
overflow-y: auto;
|
overflow-y: auto;
|
||||||
overflow: hidden;
|
overflow-x: hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
.grid-row {
|
.grid-row {
|
||||||
display: grid;
|
display: flex;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
padding: 0 $s-12;
|
gap: 24px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.grid-item {
|
.grid-item {
|
||||||
|
@ -24,9 +27,7 @@
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
flex: 1 0 $s-260;
|
margin: $s-12 0;
|
||||||
height: $s-232;
|
|
||||||
margin: $s-12 $s-16 $s-16 $s-8;
|
|
||||||
position: relative;
|
position: relative;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
|
|
||||||
|
@ -38,17 +39,16 @@
|
||||||
button {
|
button {
|
||||||
background-color: transparent;
|
background-color: transparent;
|
||||||
border: none;
|
border: none;
|
||||||
}
|
padding: 0 $s-6;
|
||||||
|
|
||||||
@media #{$bp-max-1366} {
|
|
||||||
height: $s-200;
|
|
||||||
flex: 1 0 $s-232;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.grid-item-th {
|
.grid-item-th {
|
||||||
border-radius: $br-4;
|
border-radius: $br-4;
|
||||||
text-align: initial;
|
text-align: initial;
|
||||||
|
|
||||||
|
width: var(--th-width, #{$thumbnail-default-width});
|
||||||
|
height: calc(var(--th-width, #{$thumbnail-default-width}) * #{$thumbnail-aspect-ration});
|
||||||
|
|
||||||
img {
|
img {
|
||||||
object-fit: contain;
|
object-fit: contain;
|
||||||
}
|
}
|
||||||
|
@ -58,7 +58,8 @@
|
||||||
border-radius: $br-4;
|
border-radius: $br-4;
|
||||||
border: $br-2 solid $da-primary;
|
border: $br-2 solid $da-primary;
|
||||||
text-align: initial;
|
text-align: initial;
|
||||||
max-height: $s-160;
|
width: calc(var(--th-width) + $s-12);
|
||||||
|
height: calc(var(--th-width, #{$thumbnail-default-width}) * #{$thumbnail-aspect-ration});
|
||||||
}
|
}
|
||||||
|
|
||||||
&.overlay {
|
&.overlay {
|
||||||
|
@ -81,6 +82,7 @@
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: 1fr auto;
|
grid-template-columns: 1fr auto;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
|
max-width: var(--th-width, $thumbnail-default-width);
|
||||||
}
|
}
|
||||||
|
|
||||||
.item-info {
|
.item-info {
|
||||||
|
@ -261,8 +263,7 @@
|
||||||
background-size: auto 80%;
|
background-size: auto 80%;
|
||||||
background-repeat: no-repeat;
|
background-repeat: no-repeat;
|
||||||
|
|
||||||
height: $s-232;
|
height: 100%;
|
||||||
max-height: $s-160;
|
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
position: relative;
|
position: relative;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
|
@ -294,7 +295,6 @@
|
||||||
|
|
||||||
.grid-item.project-th.library {
|
.grid-item.project-th.library {
|
||||||
height: $s-612;
|
height: $s-612;
|
||||||
width: $s-300;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.grid-item-th.library {
|
.grid-item-th.library {
|
||||||
|
|
|
@ -51,10 +51,10 @@
|
||||||
|
|
||||||
(if new-css-system
|
(if new-css-system
|
||||||
[:*
|
[:*
|
||||||
[:header {:class (stl/css :dashboard-header) :ref rowref}
|
[:header {:class (stl/css :dashboard-header)}
|
||||||
[:div#dashboard-libraries-title {:class (stl/css :dashboard-title)}
|
[:div#dashboard-libraries-title {:class (stl/css :dashboard-title)}
|
||||||
[:h1 (tr "dashboard.libraries-title")]]]
|
[:h1 (tr "dashboard.libraries-title")]]]
|
||||||
[:section {:class (stl/css :dashboard-container :no-bg :dashboard-shared)}
|
[:section {:class (stl/css :dashboard-container :no-bg :dashboard-shared) :ref rowref}
|
||||||
[:& grid {:files files
|
[:& grid {:files files
|
||||||
:project default-project
|
:project default-project
|
||||||
:origin :libraries
|
:origin :libraries
|
||||||
|
|
|
@ -17,10 +17,6 @@
|
||||||
&.dashboard-projects {
|
&.dashboard-projects {
|
||||||
user-select: none;
|
user-select: none;
|
||||||
}
|
}
|
||||||
&.dashboard-shared {
|
|
||||||
width: calc(100vw - $s-320);
|
|
||||||
margin-right: $s-52;
|
|
||||||
}
|
|
||||||
|
|
||||||
&.search {
|
&.search {
|
||||||
margin-top: $s-12;
|
margin-top: $s-12;
|
||||||
|
|
|
@ -10,9 +10,7 @@
|
||||||
.grid-empty-placeholder {
|
.grid-empty-placeholder {
|
||||||
border-radius: $br-12;
|
border-radius: $br-12;
|
||||||
display: grid;
|
display: grid;
|
||||||
padding: $s-12;
|
padding: $s-12 0;
|
||||||
margin-right: $s-12;
|
|
||||||
height: $s-232;
|
|
||||||
|
|
||||||
&.loader {
|
&.loader {
|
||||||
justify-items: center;
|
justify-items: center;
|
||||||
|
|
|
@ -246,7 +246,6 @@
|
||||||
:edition? (= (:id project) edit-id)})
|
:edition? (= (:id project) edit-id)})
|
||||||
|
|
||||||
[rowref limit] (hooks/use-dynamic-grid-item-width)
|
[rowref limit] (hooks/use-dynamic-grid-item-width)
|
||||||
|
|
||||||
on-nav
|
on-nav
|
||||||
(mf/use-fn
|
(mf/use-fn
|
||||||
(mf/deps project-id team-id)
|
(mf/deps project-id team-id)
|
||||||
|
@ -344,7 +343,7 @@
|
||||||
|
|
||||||
(if new-css-system
|
(if new-css-system
|
||||||
[:article {:class (stl/css-case :dashboard-project-row true :first first?)}
|
[:article {:class (stl/css-case :dashboard-project-row true :first first?)}
|
||||||
[:header {:class (stl/css :project) :ref rowref}
|
[:header {:class (stl/css :project)}
|
||||||
[:div {:class (stl/css :project-name-wrapper)}
|
[:div {:class (stl/css :project-name-wrapper)}
|
||||||
(if (:edition? @local)
|
(if (:edition? @local)
|
||||||
[:& inline-edition {:content (:name project)
|
[:& inline-edition {:content (:name project)
|
||||||
|
@ -403,12 +402,13 @@
|
||||||
:on-key-down handle-menu-click}
|
:on-key-down handle-menu-click}
|
||||||
i/actions]]]]
|
i/actions]]]]
|
||||||
|
|
||||||
[:& line-grid
|
[:div {:class (stl/css :grid-container) :ref rowref}
|
||||||
{:project project
|
[:& line-grid
|
||||||
:team team
|
{:project project
|
||||||
:files files
|
:team team
|
||||||
:create-fn create-file
|
:files files
|
||||||
:limit limit}]
|
:create-fn create-file
|
||||||
|
:limit limit}]]
|
||||||
|
|
||||||
(when (and (> limit 0)
|
(when (and (> limit 0)
|
||||||
(> file-count limit))
|
(> file-count limit))
|
||||||
|
|
|
@ -145,6 +145,11 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.grid-container {
|
||||||
|
width: 100%;
|
||||||
|
padding: 0 $s-16;
|
||||||
|
}
|
||||||
|
|
||||||
&:hover,
|
&:hover,
|
||||||
&:focus,
|
&:focus,
|
||||||
&:focus-within {
|
&:focus-within {
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
|
||||||
;; This Source Code Form is subject to the terms of the Mozilla Public
|
;; This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
@ -350,9 +351,7 @@
|
||||||
(defn use-dynamic-grid-item-width
|
(defn use-dynamic-grid-item-width
|
||||||
([] (use-dynamic-grid-item-width nil))
|
([] (use-dynamic-grid-item-width nil))
|
||||||
([itemsize]
|
([itemsize]
|
||||||
(let [;; NOTE: we pass a function to use-state for avoid repeatedly
|
(let [width* (mf/use-state nil)
|
||||||
;; lookup `:items-width` on storage on each render
|
|
||||||
width* (mf/use-state #(:items-width @storage))
|
|
||||||
width (deref width*)
|
width (deref width*)
|
||||||
|
|
||||||
rowref (mf/use-ref)
|
rowref (mf/use-ref)
|
||||||
|
@ -365,20 +364,26 @@
|
||||||
ratio (if (some? width) (/ width itemsize) 0)
|
ratio (if (some? width) (/ width itemsize) 0)
|
||||||
nitems (mth/floor ratio)
|
nitems (mth/floor ratio)
|
||||||
limit (mth/min 10 nitems)
|
limit (mth/min 10 nitems)
|
||||||
limit (mth/max 1 limit)]
|
limit (mth/max 1 limit)
|
||||||
|
|
||||||
|
th-size (- (/ (- width (* (dec limit) 24)) limit) 12)]
|
||||||
|
|
||||||
|
(mf/with-effect
|
||||||
|
[th-size]
|
||||||
|
(when th-size
|
||||||
|
(let [node (mf/ref-val rowref)]
|
||||||
|
(.setProperty (.-style node) "--th-width" (str th-size "px")))))
|
||||||
|
|
||||||
(mf/with-effect []
|
(mf/with-effect []
|
||||||
(let [node (mf/ref-val rowref)
|
(let [node (mf/ref-val rowref)
|
||||||
mnt? (volatile! true)
|
mnt? (volatile! true)
|
||||||
sub (->> (wapi/observe-resize node)
|
sub (->> (wapi/observe-resize node)
|
||||||
(rx/observe-on :af)
|
|
||||||
(rx/subs (fn [entries]
|
(rx/subs (fn [entries]
|
||||||
(let [row (first entries)
|
(let [row (first entries)
|
||||||
row-rect (.-contentRect ^js row)
|
row-rect (.-contentRect ^js row)
|
||||||
row-width (.-width ^js row-rect)]
|
row-width (.-width ^js row-rect)]
|
||||||
(when @mnt?
|
(when @mnt?
|
||||||
(reset! width* row-width)
|
(reset! width* row-width))))))]
|
||||||
(swap! storage assoc :items-width row-width))))))]
|
|
||||||
(fn []
|
(fn []
|
||||||
(vreset! mnt? false)
|
(vreset! mnt? false)
|
||||||
(rx/dispose! sub))))
|
(rx/dispose! sub))))
|
||||||
|
|
Loading…
Add table
Reference in a new issue