mirror of https://github.com/usememos/memos
chore: add memo resources component
parent
fbce43870f
commit
5fa9aa3c22
@ -0,0 +1,28 @@
|
|||||||
|
import { IMAGE_URL_REG } from "../helpers/marked";
|
||||||
|
import Only from "./common/OnlyWhen";
|
||||||
|
import Image from "./Image";
|
||||||
|
import "../less/memo-resources.less";
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
className?: string;
|
||||||
|
memo: Memo;
|
||||||
|
}
|
||||||
|
|
||||||
|
const MemoResources: React.FC<Props> = (props: Props) => {
|
||||||
|
const { className, memo } = props;
|
||||||
|
const imageUrls = Array.from(memo.content.match(IMAGE_URL_REG) ?? []).map((s) => s.replace(IMAGE_URL_REG, "$1"));
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="resource-wrapper">
|
||||||
|
<Only when={imageUrls.length > 0}>
|
||||||
|
<div className={`images-wrapper ${className ?? ""}`}>
|
||||||
|
{imageUrls.map((imgUrl, idx) => (
|
||||||
|
<Image className="memo-img" key={idx} imgUrl={imgUrl} />
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</Only>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default MemoResources;
|
@ -0,0 +1,19 @@
|
|||||||
|
@import "./mixin.less";
|
||||||
|
|
||||||
|
.resource-wrapper {
|
||||||
|
@apply w-full flex flex-col justify-start items-start;
|
||||||
|
|
||||||
|
> .images-wrapper {
|
||||||
|
@apply flex flex-row justify-start items-start mt-2 w-full overflow-x-auto overflow-y-hidden pb-1;
|
||||||
|
.pretty-scroll-bar(0, 2px);
|
||||||
|
|
||||||
|
> .memo-img {
|
||||||
|
@apply mr-2 last:mr-0 w-auto h-auto shrink-0 grow-0 overflow-y-hidden;
|
||||||
|
.hide-scroll-bar();
|
||||||
|
|
||||||
|
> img {
|
||||||
|
@apply w-auto max-h-40 rounded-lg;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue