@volchoklv/socialfire-widget
v1.0.5
Published
Embeddable Instagram feed widget - React & vanilla JS
Maintainers
Readme
@volchoklv/socialfire-widget
Embeddable Instagram feed widget for React and vanilla JavaScript.
Installation
NPM (React/Next.js)
npm install @volchoklv/socialfire-widgetCDN (Vanilla JS)
<script src="https://cdn.jsdelivr.net/npm/@volchoklv/socialfire-widget/dist/widget.js" type="module"></script>Usage
React Component
import { SocialfireWidget } from '@volchoklv/socialfire-widget';
function App() {
return (
<SocialfireWidget
feedId="69659d2ea71efefb3b69f35f"
apiUrl="https://your-api.com"
onLoad={(feed) => console.log('Feed loaded:', feed)}
onError={(error) => console.error('Error:', error)}
/>
);
}Note: The
feedIdmust be a MongoDB ObjectId (24 character hex string). Slugs are not supported for security and multi-tenant compatibility.
Props
| Prop | Type | Required | Description |
|------|------|----------|-------------|
| feedId | string | Yes | Feed ID (MongoDB ObjectId) |
| apiUrl | string | No | API base URL (defaults to window.location.origin) |
| className | string | No | Additional CSS classes |
| onLoad | (feed: SocialfireFeed) => void | No | Callback when feed loads |
| onError | (error: Error) => void | No | Callback on error |
| loadingComponent | React.ReactNode | No | Custom loading component |
| errorComponent | (error: Error) => React.ReactNode | No | Custom error component |
Vanilla JavaScript (Web Component)
<!DOCTYPE html>
<html>
<head>
<script src="https://cdn.jsdelivr.net/npm/@volchoklv/socialfire-widget/dist/widget.js" type="module"></script>
</head>
<body>
<socialfire-widget
feed-id="69659d2ea71efefb3b69f35f"
api-url="https://your-api.com">
</socialfire-widget>
<script>
const widget = document.querySelector('socialfire-widget');
widget.addEventListener('load', (event) => {
console.log('Feed loaded:', event.detail);
});
widget.addEventListener('error', (event) => {
console.error('Error:', event.detail);
});
</script>
</body>
</html>Note: The
feed-idattribute must be a MongoDB ObjectId (24 character hex string). Slugs are not supported for security and multi-tenant compatibility.
Attributes
| Attribute | Type | Required | Description |
|-----------|------|----------|-------------|
| feed-id | string | Yes | Feed ID (MongoDB ObjectId) |
| api-url | string | No | API base URL (defaults to current origin) |
Events
| Event | Detail | Description |
|-------|--------|-------------|
| load | SocialfireFeed | Fired when feed loads successfully |
| error | Error | Fired when an error occurs |
TypeScript Support
Full TypeScript support is included with exported types:
import type { SocialfirePost, SocialfireFeed, SocialfireWidgetProps } from '@volchoklv/socialfire-widget';API Response Format
The widget expects the API endpoint to return JSON in this format:
{
"feedId": "507f1f77bcf86cd799439011",
"slug": "homepage-feed",
"name": "My Instagram Feed",
"layout": "GRID",
"columns": 3,
"rows": 3,
"gap": 16,
"showCaptions": true,
"showLikes": true,
"showComments": true,
"posts": [
{
"id": "17895695668004550",
"caption": "Post caption text",
"mediaType": "IMAGE",
"mediaUrl": "https://scontent.cdninstagram.com/...",
"permalink": "https://www.instagram.com/p/ABC123/",
"thumbnailUrl": null,
"timestamp": "2024-01-15T10:30:00+0000",
"likeCount": 42,
"commentsCount": 5
}
],
"cachedAt": "2024-01-15T10:00:00.000Z",
"expiresAt": "2024-01-15T11:00:00.000Z"
}Browser Compatibility
- Chrome/Edge 90+
- Firefox 88+
- Safari 15+
- Mobile Safari iOS 15+
- Chrome Android 90+
Requires:
- Custom Elements v1 (Web Components)
- Shadow DOM v1
- Fetch API
- ES2020 features
Bundle Size
- React component: ~6 KB gzipped
- Vanilla Web Component: ~2 KB gzipped
Author
Volchok - volchok.dev
License
MIT
Links
- Socialfire - Create and manage Instagram feeds
- Documentation
- GitHub Repository
- NPM Package
