features.tsx (2994B)
1 import { Section } from "../util/section"; 2 import { Container } from "../util/container"; 3 import { Icon } from "../util/icon"; 4 import { iconSchema } from "../util/icon"; 5 import { 6 PageBlocksFeatures, 7 PageBlocksFeaturesItems, 8 } from "../../tina/__generated__/types"; 9 import { tinaField } from "tinacms/dist/react"; 10 11 export const Feature = ({ 12 featuresColor, 13 data, 14 }: { 15 featuresColor: string; 16 data: PageBlocksFeaturesItems; 17 }) => { 18 return ( 19 <div 20 data-tina-field={tinaField(data)} 21 className="flex-1 flex flex-col gap-6 text-center items-center lg:items-start lg:text-left max-w-xl mx-auto" 22 style={{ flexBasis: "16rem" }} 23 > 24 {data.icon && ( 25 <Icon 26 tinaField={tinaField(data, "icon")} 27 parentColor={featuresColor} 28 data={{ size: "large", ...data.icon }} 29 /> 30 )} 31 {data.title && ( 32 <h3 33 data-tina-field={tinaField(data, "title")} 34 className="text-2xl font-semibold title-font" 35 > 36 {data.title} 37 </h3> 38 )} 39 {data.text && ( 40 <p 41 data-tina-field={tinaField(data, "text")} 42 className="text-base opacity-80 leading-relaxed" 43 > 44 {data.text} 45 </p> 46 )} 47 </div> 48 ); 49 }; 50 51 export const Features = ({ data }: { data: PageBlocksFeatures }) => { 52 return ( 53 <Section color={data.color}> 54 <Container 55 className={`flex flex-wrap gap-x-10 gap-y-8 text-left`} 56 size="large" 57 > 58 {data.items && 59 data.items.map(function (block, i) { 60 return <Feature featuresColor={data.color} key={i} data={block} />; 61 })} 62 </Container> 63 </Section> 64 ); 65 }; 66 67 const defaultFeature = { 68 title: "Here's Another Feature", 69 text: "This is where you might talk about the feature, if this wasn't just filler text.", 70 icon: { 71 color: "", 72 style: "float", 73 name: "", 74 }, 75 }; 76 77 export const featureBlockSchema = { 78 name: "features", 79 label: "Features", 80 ui: { 81 previewSrc: "/blocks/features.png", 82 defaultItem: { 83 items: [defaultFeature, defaultFeature, defaultFeature], 84 }, 85 }, 86 fields: [ 87 { 88 type: "object", 89 label: "Feature Items", 90 name: "items", 91 list: true, 92 ui: { 93 itemProps: (item) => { 94 return { 95 label: item?.title, 96 }; 97 }, 98 defaultItem: { 99 ...defaultFeature, 100 }, 101 }, 102 fields: [ 103 iconSchema, 104 { 105 type: "string", 106 label: "Title", 107 name: "title", 108 }, 109 { 110 type: "string", 111 label: "Text", 112 name: "text", 113 ui: { 114 component: "textarea", 115 }, 116 }, 117 ], 118 }, 119 { 120 type: "string", 121 label: "Color", 122 name: "color", 123 options: [ 124 { label: "Default", value: "default" }, 125 { label: "Tint", value: "tint" }, 126 { label: "Primary", value: "primary" }, 127 ], 128 }, 129 ], 130 };